interface.js: implement drop-down input
This commit is contained in:
parent
ab676217cd
commit
3caf1b72ba
@ -194,6 +194,36 @@ class Form extends InterfaceElement {
|
|||||||
return this.appendElement(new FormElement(params));
|
return this.appendElement(new FormElement(params));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createDropDown(params) {
|
||||||
|
// example for params.options:
|
||||||
|
/*
|
||||||
|
[
|
||||||
|
{
|
||||||
|
value: "volvo"
|
||||||
|
name: "Volvo"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: "benz"
|
||||||
|
name: "Mercedes Benz"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
*/
|
||||||
|
params.fragment = new DocumentFragment();
|
||||||
|
params.tag = document.createElement("select");
|
||||||
|
params.labelTag = document.createElement("label");
|
||||||
|
params.labelTag.appendChild(document.createTextNode(params.label));
|
||||||
|
params.fragment.appendChild(params.labelTag);
|
||||||
|
params.fragment.appendChild(params.tag);
|
||||||
|
dataTypeSupports(params, ["category"]);
|
||||||
|
for (const option of params.options) {
|
||||||
|
let optTag = document.createElement("option");
|
||||||
|
optTag.value = option.value;
|
||||||
|
optTag.appendChild(document.createTextNode(option.name));
|
||||||
|
params.tag.appendChild(optTag);
|
||||||
|
}
|
||||||
|
return this.appendElement(new FormElement(params));
|
||||||
|
}
|
||||||
|
|
||||||
createTextArea(params) {
|
createTextArea(params) {
|
||||||
params.tag = document.createElement("textarea");
|
params.tag = document.createElement("textarea");
|
||||||
dataTypeSupports(params, ["plaintext", "b64", "json-b64"]);
|
dataTypeSupports(params, ["plaintext", "b64", "json-b64"]);
|
||||||
@ -316,6 +346,8 @@ class FormElement extends InterfaceElement {
|
|||||||
}
|
}
|
||||||
case "bool":
|
case "bool":
|
||||||
return this.handle.checked;
|
return this.handle.checked;
|
||||||
|
case "category":
|
||||||
|
return this.handle.value;
|
||||||
case "none":
|
case "none":
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -335,6 +367,9 @@ class FormElement extends InterfaceElement {
|
|||||||
case "bool":
|
case "bool":
|
||||||
this.handle.checked = x;
|
this.handle.checked = x;
|
||||||
break;
|
break;
|
||||||
|
case "category":
|
||||||
|
this.handle.value = x;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user