Intermediate refactoring

This commit is contained in:
Pieter Vander Vennet 2020-07-20 18:24:00 +02:00
parent 069cddf034
commit 7b80e945bb
16 changed files with 43 additions and 44 deletions

View file

@ -26,7 +26,7 @@ export class InputElementWrapper<T> extends InputElement<T>{
return this.input.GetValue();
}
protected InnerRender(): string {
InnerRender(): string {
return this.pre.Render() + this.input.Render() + this.post.Render();
}

View file

@ -62,7 +62,7 @@ export class RadioButton<T> extends InputElement<T> {
return 'radio-' + this.id + '-' + i;
}
protected InnerRender(): string {
InnerRender(): string {
let body = "";
let i = 0;
@ -83,14 +83,16 @@ export class RadioButton<T> extends InputElement<T> {
if (t === undefined) {
return;
}
console.log("Trying to find an option for", t)
// We check that what is selected matches the previous rendering
for (let i = 0; i < this._elements.length; i++) {
const e = this._elements[i];
if (e.IsValid(t)) {
this._selectedElementIndex.setData(i);
e.GetValue().setData(t);
const radio = document.getElementById(this.IdFor(i));
// @ts-ignore
document.getElementById(this.IdFor(i)).checked = true;
radio?.checked = true;
return;
}

View file

@ -18,8 +18,8 @@ export class TextField<T> extends InputElement<T> {
constructor(options: {
placeholder?: string | UIElement,
toString?: (t: T) => string,
fromString?: (string: string) => T,
toString: (t: T) => string,
fromString: (string: string) => T,
value?: UIEventSource<T>
}) {
super(undefined);
@ -33,15 +33,18 @@ export class TextField<T> extends InputElement<T> {
this.mappedValue.addCallback((t) => this.value.setData(options.toString(t)));
this._placeholder =
typeof(options.placeholder) === "string" ? new FixedUiElement(options.placeholder) :
(options.placeholder ?? new FixedUiElement(""));
options.placeholder = options.placeholder ?? "";
if (options.placeholder instanceof UIElement) {
this._placeholder = options.placeholder
} else {
this._placeholder = new FixedUiElement(options.placeholder);
}
this._toString = options.toString ?? ((t) => ("" + t));
const self = this;
this.mappedValue.addCallback((t) => {
if (t === undefined && t === null) {
if (t === undefined || t === null) {
return;
}
const field = document.getElementById('text-' + this.id);
@ -57,7 +60,7 @@ export class TextField<T> extends InputElement<T> {
return this.mappedValue;
}
protected InnerRender(): string {
InnerRender(): string {
return "<form onSubmit='return false' class='form-text-field'>" +
"<input type='text' placeholder='" + this._placeholder.InnerRender() + "' id='text-" + this.id + "'>" +
"</form>";