diff --git a/UI/Input/MultiLingualTextFields.ts b/UI/Input/MultiLingualTextFields.ts index 5e83ff5..d1f69fb 100644 --- a/UI/Input/MultiLingualTextFields.ts +++ b/UI/Input/MultiLingualTextFields.ts @@ -6,13 +6,11 @@ export default class MultiLingualTextFields extends InputElement { private _fields: Map = new Map(); private readonly _value: UIEventSource; public readonly IsSelected: UIEventSource = new UIEventSource(false); - constructor(languages: UIEventSource, textArea: boolean = false, value: UIEventSource>> = undefined) { super(undefined); this._value = value ?? new UIEventSource({}); - this._value.addCallbackAndRun(latestData => { if (typeof (latestData) === "string") { console.warn("Refusing string for multilingual input", latestData); diff --git a/UI/Input/MultiTagInput.ts b/UI/Input/MultiTagInput.ts index 20bd3e2..30295bc 100644 --- a/UI/Input/MultiTagInput.ts +++ b/UI/Input/MultiTagInput.ts @@ -3,7 +3,6 @@ import TagInput from "./SingleTagInput"; import {MultiInput} from "./MultiInput"; export class MultiTagInput extends MultiInput { - constructor(value: UIEventSource = new UIEventSource([])) { super("Add a new tag", diff --git a/UI/Input/RadioButton.ts b/UI/Input/RadioButton.ts index 415760f..2f46c2e 100644 --- a/UI/Input/RadioButton.ts +++ b/UI/Input/RadioButton.ts @@ -11,8 +11,7 @@ export class RadioButton extends InputElement { private readonly value: UIEventSource; private readonly _elements: InputElement[] private readonly _selectFirstAsDefault: boolean; - - + constructor(elements: InputElement[], selectFirstAsDefault = true) { super(undefined); @@ -20,7 +19,6 @@ export class RadioButton extends InputElement { this._selectFirstAsDefault = selectFirstAsDefault; const self = this; - this.value = UIEventSource.flatten(this._selectedElementIndex.map( (selectedIndex) => { diff --git a/UI/Input/SingleTagInput.ts b/UI/Input/SingleTagInput.ts index e3a6d5a..e7525da 100644 --- a/UI/Input/SingleTagInput.ts +++ b/UI/Input/SingleTagInput.ts @@ -22,7 +22,6 @@ export default class SingleTagInput extends InputElement { constructor(value: UIEventSource = undefined) { super(undefined); this._value = value ?? new UIEventSource(""); - this.helpMessage = new VariableUiElement(this._value.map(tagDef => { try { FromJSON.Tag(tagDef, ""); diff --git a/UI/Input/TextField.ts b/UI/Input/TextField.ts index d6f1a3e..1d75292 100644 --- a/UI/Input/TextField.ts +++ b/UI/Input/TextField.ts @@ -10,7 +10,7 @@ export class TextField extends InputElement { public readonly IsSelected: UIEventSource = new UIEventSource(false); private readonly _isArea: boolean; private readonly _textAreaRows: number; - + constructor(options?: { placeholder?: string | UIElement, value?: UIEventSource, @@ -52,7 +52,6 @@ export class TextField extends InputElement { field.value = t; }); this.dumbMode = false; - this.SetClass("deadbeef") } GetValue(): UIEventSource { @@ -72,18 +71,18 @@ export class TextField extends InputElement { ``; } - Update() { - console.log("Updating TF") - super.Update(); - } InnerUpdate() { - console.log("Inner Updating TF") const field = document.getElementById("txt-" + this.id); const self = this; field.oninput = () => { + // @ts-ignore + var endDistance = field.value.length - field.selectionEnd; // @ts-ignore self.value.setData(field.value); + // Setting the value might cause the value to be set again. We keep the distance _to the end_ stable, as phone number formatting might cause the start to change + // See https://github.com/pietervdvn/MapComplete/issues/103 + self.SetCursorPosition(field.value.length - endDistance); }; if (this.value.data !== undefined && this.value.data !== null) { @@ -105,7 +104,7 @@ export class TextField extends InputElement { } public SetCursorPosition(i: number) { - const field = document.getElementById('text-' + this.id); + const field = document.getElementById('txt-' + this.id); if(field === undefined || field === null){ return; } @@ -116,6 +115,7 @@ export class TextField extends InputElement { field.focus(); // @ts-ignore field.setSelectionRange(i, i); + } IsValid(t: string): boolean { diff --git a/UI/Input/ValidatedTextField.ts b/UI/Input/ValidatedTextField.ts index e007465..9c53373 100644 --- a/UI/Input/ValidatedTextField.ts +++ b/UI/Input/ValidatedTextField.ts @@ -90,7 +90,7 @@ export default class ValidatedTextField { return parsePhoneNumberFromString(str, country?.toUpperCase())?.isValid() ?? false }, (str, country: any) => { - console.log("country formatting", country) + console.log("reformatting phone nuber",str, "for locale", country) return parsePhoneNumberFromString(str, country?.toUpperCase()).formatInternational() } )