SimpleChat:UI:Select: dict-name-value, value wrt default, change
Take a dict/object of name-value pairs instead of just names. Inturn specify the actual value wrt default, rather than the string representing that value. Trap the needed change event rather than click wrt select.
This commit is contained in:
parent
1e47a48b30
commit
94bc0b08d8
2 changed files with 6 additions and 6 deletions
|
@ -586,7 +586,7 @@ class Me {
|
||||||
});
|
});
|
||||||
elDiv.appendChild(bb);
|
elDiv.appendChild(bb);
|
||||||
|
|
||||||
let sel = ui.el_create_select("SetChatHistoryInCtxt", Object.keys(this.sRecentUserMsgCnt), "Last0", (val)=>{
|
let sel = ui.el_create_select("SetChatHistoryInCtxt", this.sRecentUserMsgCnt, this.iRecentUserMsgCnt, (val)=>{
|
||||||
this.iRecentUserMsgCnt = this.sRecentUserMsgCnt[val];
|
this.iRecentUserMsgCnt = this.sRecentUserMsgCnt[val];
|
||||||
});
|
});
|
||||||
elDiv.appendChild(sel);
|
elDiv.appendChild(sel);
|
||||||
|
|
|
@ -86,19 +86,19 @@ export function el_create_boolbutton(id, texts, defaultValue, cb) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} id
|
* @param {string} id
|
||||||
* @param {string[]} options
|
* @param {Object<string,*>} options
|
||||||
* @param {string} defaultOption
|
* @param {*} defaultOption
|
||||||
* @param {function(string):void} cb
|
* @param {function(string):void} cb
|
||||||
*/
|
*/
|
||||||
export function el_create_select(id, options, defaultOption, cb) {
|
export function el_create_select(id, options, defaultOption, cb) {
|
||||||
let el = document.createElement("select");
|
let el = document.createElement("select");
|
||||||
el["xselected"] = defaultOption;
|
el["xselected"] = defaultOption;
|
||||||
el["xoptions"] = structuredClone(options);
|
el["xoptions"] = structuredClone(options);
|
||||||
for(let cur of options) {
|
for(let cur of Object.keys(options)) {
|
||||||
let op = document.createElement("option");
|
let op = document.createElement("option");
|
||||||
op.value = cur;
|
op.value = cur;
|
||||||
op.innerText = cur;
|
op.innerText = cur;
|
||||||
if (cur == defaultOption) {
|
if (options[cur] == defaultOption) {
|
||||||
op.selected = true;
|
op.selected = true;
|
||||||
}
|
}
|
||||||
el.appendChild(op);
|
el.appendChild(op);
|
||||||
|
@ -107,7 +107,7 @@ export function el_create_select(id, options, defaultOption, cb) {
|
||||||
el.id = id;
|
el.id = id;
|
||||||
el.name = id;
|
el.name = id;
|
||||||
}
|
}
|
||||||
el.addEventListener('click', (ev)=>{
|
el.addEventListener('change', (ev)=>{
|
||||||
let target = /** @type{HTMLSelectElement} */(ev.target);
|
let target = /** @type{HTMLSelectElement} */(ev.target);
|
||||||
console.log("DBUG:UI:Select:", id, ":", target.value);
|
console.log("DBUG:UI:Select:", id, ":", target.value);
|
||||||
cb(target.value);
|
cb(target.value);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue