Fixed input for sets (fix #112)
This commit is contained in:
parent
e0f2f70c2e
commit
3653c3ecaa
3 changed files with 34 additions and 30 deletions
|
@ -13,7 +13,8 @@ export default class InputElementMap<T, X> extends InputElement<X> {
|
||||||
constructor(inputElement: InputElement<T>,
|
constructor(inputElement: InputElement<T>,
|
||||||
isSame: (x0: X, x1: X) => boolean,
|
isSame: (x0: X, x1: X) => boolean,
|
||||||
toX: (t: T) => X,
|
toX: (t: T) => X,
|
||||||
fromX: (x: X) => T
|
fromX: (x: X) => T,
|
||||||
|
extraSources: UIEventSource<any>[] = []
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this.isSame = isSame;
|
this.isSame = isSame;
|
||||||
|
@ -30,7 +31,7 @@ export default class InputElementMap<T, X> extends InputElement<X> {
|
||||||
return currentX;
|
return currentX;
|
||||||
}
|
}
|
||||||
return newX;
|
return newX;
|
||||||
}), [], x => {
|
}), extraSources, x => {
|
||||||
const newT = fromX(x);
|
const newT = fromX(x);
|
||||||
return newT;
|
return newT;
|
||||||
});
|
});
|
||||||
|
|
|
@ -224,8 +224,22 @@ export class TextField<T> extends InputElement<T> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SetCursorPosition(i: number) {
|
||||||
|
const field = document.getElementById('text-' + this.id);
|
||||||
|
if(field === undefined || field === null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(i === -1){
|
||||||
|
// @ts-ignore
|
||||||
|
i = field.value.length;
|
||||||
|
}
|
||||||
|
field.focus();
|
||||||
|
// @ts-ignore
|
||||||
|
field.setSelectionRange(i, i);
|
||||||
|
}
|
||||||
|
|
||||||
IsValid(t: T): boolean {
|
IsValid(t: T): boolean {
|
||||||
if(t === undefined || t === null){
|
if (t === undefined || t === null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const result = this._toString(t);
|
const result = this._toString(t);
|
||||||
|
|
|
@ -13,7 +13,6 @@ import {CheckBoxes} from "./Input/Checkboxes";
|
||||||
import {InputElement} from "./Input/InputElement";
|
import {InputElement} from "./Input/InputElement";
|
||||||
import {SaveButton} from "./SaveButton";
|
import {SaveButton} from "./SaveButton";
|
||||||
import {RadioButton} from "./Input/RadioButton";
|
import {RadioButton} from "./Input/RadioButton";
|
||||||
import {InputElementWrapper} from "./Input/InputElementWrapper";
|
|
||||||
import {FixedInputElement} from "./Input/FixedInputElement";
|
import {FixedInputElement} from "./Input/FixedInputElement";
|
||||||
import {TextField, ValidatedTextField} from "./Input/TextField";
|
import {TextField, ValidatedTextField} from "./Input/TextField";
|
||||||
import {TagRenderingOptions} from "../Customizations/TagRenderingOptions";
|
import {TagRenderingOptions} from "../Customizations/TagRenderingOptions";
|
||||||
|
@ -205,7 +204,7 @@ export class TagRendering extends UIElement implements TagDependantUIElement {
|
||||||
InputElement<TagsFilter> {
|
InputElement<TagsFilter> {
|
||||||
|
|
||||||
|
|
||||||
let freeformElement: InputElement<TagsFilter> = undefined;
|
let freeformElement: TextField<TagsFilter> = undefined;
|
||||||
if (options.freeform !== undefined) {
|
if (options.freeform !== undefined) {
|
||||||
freeformElement = this.InputForFreeForm(options.freeform);
|
freeformElement = this.InputForFreeForm(options.freeform);
|
||||||
}
|
}
|
||||||
|
@ -264,29 +263,24 @@ export class TagRendering extends UIElement implements TagDependantUIElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return indices;
|
return indices;
|
||||||
}
|
},
|
||||||
|
[freeformElement?.GetValue()]
|
||||||
);
|
);
|
||||||
|
|
||||||
freeformElement?.IsSelected.addCallback((isSelected) => {
|
freeformElement?.GetValue()?.addCallbackAndRun(value => {
|
||||||
console.log("SELECTED FF", isSelected)
|
|
||||||
if (isSelected) {
|
|
||||||
const es = checkBoxes.GetValue();
|
const es = checkBoxes.GetValue();
|
||||||
const i = elements.length - 1
|
const i = elements.length - 1;
|
||||||
if (es.data.indexOf(i) >= 0) {
|
const index = es.data.indexOf(i);
|
||||||
return;
|
if (value === undefined) {
|
||||||
|
if (index >= 0) {
|
||||||
|
es.data.splice(index, 1);
|
||||||
|
es.ping();
|
||||||
}
|
}
|
||||||
|
} else if (index < 0) {
|
||||||
es.data.push(i);
|
es.data.push(i);
|
||||||
es.ping();
|
es.ping();
|
||||||
}
|
}
|
||||||
});
|
freeformElement.SetCursorPosition(-1);
|
||||||
|
|
||||||
freeformElement?.GetValue()?.addCallback(() => {
|
|
||||||
const es = checkBoxes.GetValue();
|
|
||||||
const i = elements.length - 1
|
|
||||||
if (es.data.indexOf(i) < 0) {
|
|
||||||
es.data.push(i);
|
|
||||||
es.ping();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return inputEl;
|
return inputEl;
|
||||||
|
@ -314,7 +308,7 @@ export class TagRendering extends UIElement implements TagDependantUIElement {
|
||||||
renderTemplate: string | Translation,
|
renderTemplate: string | Translation,
|
||||||
placeholder?: string | Translation,
|
placeholder?: string | Translation,
|
||||||
extraTags?: TagsFilter,
|
extraTags?: TagsFilter,
|
||||||
}): InputElement<TagsFilter> {
|
}): TextField<TagsFilter> {
|
||||||
if (freeform?.template === undefined) {
|
if (freeform?.template === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -372,16 +366,11 @@ export class TagRendering extends UIElement implements TagDependantUIElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const textField = new TextField({
|
return new TextField({
|
||||||
placeholder: this._freeform.placeholder,
|
placeholder: this._freeform.placeholder,
|
||||||
fromString: pickString,
|
fromString: pickString,
|
||||||
toString: toString
|
toString: toString
|
||||||
});
|
});
|
||||||
|
|
||||||
const pre = prepost[0] !== undefined ? this.ApplyTemplate(prepost[0]) : "";
|
|
||||||
const post = prepost[2] !== undefined ? this.ApplyTemplate(prepost[2]) : "";
|
|
||||||
|
|
||||||
return new InputElementWrapper(pre, textField, post);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue