Skip to content

Commit

Permalink
#16: correct handling for boatData config items
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Mar 1, 2022
1 parent e3723be commit 0b906d5
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ function resetForm(ev) {
}
}
}
el.value = v;
if (el.tagName === 'SELECT') {
setSelect(el,v);
}
else{
el.value = v;
}
el.setAttribute('data-loaded', v);
let changeEvent = new Event('change');
el.dispatchEvent(changeEvent);
Expand Down Expand Up @@ -459,14 +464,30 @@ function createInput(configItem, frame,clazz) {
return el;
}

function updateSelectList(item,slist){
item.innerHTML='';
function setSelect(item,value){
if (!item) return;
item.value=value;
if (item.value !== value){
//missing option with his value
let o=addEl('option',undefined,item,value);
o.setAttribute('value',value);
item.value=value;
}
}

function updateSelectList(item,slist,opt_keepValue){
let idx=0;
let value;
if (opt_keepValue) value=item.value;
item.innerHTML='';
slist.forEach(function (sitem) {
let sitemEl = addEl('option','',item,sitem.l);
sitemEl.setAttribute('value', sitem.v !== undefined?sitem.v:idx);
idx++;
})
if (value !== undefined){
setSelect(item,value);
}
}
function getXdrCategories(){
let rt=[];
Expand Down Expand Up @@ -1462,7 +1483,7 @@ function updateDashboard(data) {
}
if (selectChanged){
forEl('.boatDataSelect',function(el){
updateSelectList(el,selectList);
updateSelectList(el,selectList,true);
});
}
}
Expand Down

0 comments on commit 0b906d5

Please sign in to comment.