fixed dbl-fillOptions in bz-select
This commit is contained in:
@@ -333,6 +333,15 @@ menu[eicmenu] [menuitem] i[class^="icon-"] {
|
|||||||
}
|
}
|
||||||
article[eiccard] > header h1{ text-align: center; }
|
article[eiccard] > header h1{ text-align: center; }
|
||||||
|
|
||||||
|
input{
|
||||||
|
width: 100%;
|
||||||
|
border-radius: 1em;
|
||||||
|
padding-left: 1em;
|
||||||
|
box-sizing: border-box;
|
||||||
|
height: 2em;
|
||||||
|
background-color: #6B5;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
/* Customizations to buildoz*/
|
/* Customizations to buildoz*/
|
||||||
bz-select > button{
|
bz-select > button{
|
||||||
@@ -350,3 +359,4 @@ bz-select option:hover{
|
|||||||
|
|
||||||
bz-toggler div.toggle-switch span.toggle-bar { background-color: #473; }
|
bz-toggler div.toggle-switch span.toggle-bar { background-color: #473; }
|
||||||
bz-toggler div.toggle-switch span.toggle-thumb { background-color:#9D8; }
|
bz-toggler div.toggle-switch span.toggle-thumb { background-color:#9D8; }
|
||||||
|
|
||||||
|
|||||||
Vendored
+8
-1
@@ -40,6 +40,7 @@ class Buildoz extends HTMLElement {
|
|||||||
|
|
||||||
class BZselect extends Buildoz {
|
class BZselect extends Buildoz {
|
||||||
#value
|
#value
|
||||||
|
#fillFromMarkup = true
|
||||||
|
|
||||||
constructor(){
|
constructor(){
|
||||||
super()
|
super()
|
||||||
@@ -58,10 +59,13 @@ class BZselect extends Buildoz {
|
|||||||
this.prepend(this.button)
|
this.prepend(this.button)
|
||||||
this.button.addEventListener('click', this.toggle.bind(this))
|
this.button.addEventListener('click', this.toggle.bind(this))
|
||||||
this.options = this.querySelectorAll('option')
|
this.options = this.querySelectorAll('option')
|
||||||
|
if(this.#fillFromMarkup){ //can only do it once and only if fillOptions was not already called !!
|
||||||
for(const opt of this.options){
|
for(const opt of this.options){
|
||||||
opt.addEventListener('click', this.onClick.bind(this))
|
opt.addEventListener('click', this.onClick.bind(this))
|
||||||
if(opt.getAttribute('selected') !== null) this.onOption(opt.value, true)
|
if(opt.getAttribute('selected') !== null) this.onOption(opt.value, true)
|
||||||
}
|
}
|
||||||
|
this.#fillFromMarkup = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static get observedAttributes(){ // Only if you want actions on attr change
|
// static get observedAttributes(){ // Only if you want actions on attr change
|
||||||
@@ -108,17 +112,20 @@ class BZselect extends Buildoz {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addOption(value, markup){
|
addOption(value, markup){
|
||||||
|
// Caution: you can count on connectedCallback to have run already, because one might fill before adding to the DOM
|
||||||
const opt = document.createElement('option')
|
const opt = document.createElement('option')
|
||||||
opt.setAttribute('value', value)
|
opt.setAttribute('value', value)
|
||||||
opt.innerHTML = markup
|
opt.innerHTML = markup
|
||||||
opt.addEventListener('click',this.onClick.bind(this))
|
opt.addEventListener('click',this.onClick.bind(this))
|
||||||
this.append(opt)
|
this.append(opt)
|
||||||
this.options = this.querySelectorAll('option')
|
this.options = this.querySelectorAll('option')
|
||||||
|
this.#fillFromMarkup = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fillOptions(opts, erase = true){
|
fillOptions(opts, erase = true){
|
||||||
|
// Caution: you can count on connectedCallback to have run already, because one might fill before adding to the DOM
|
||||||
if(erase){
|
if(erase){
|
||||||
//this.options = this.querySelectorAll('option')
|
this.options = this.querySelectorAll('option')
|
||||||
this.options.forEach(node => { node.remove() })
|
this.options.forEach(node => { node.remove() })
|
||||||
this.options = this.querySelectorAll('option')
|
this.options = this.querySelectorAll('option')
|
||||||
this.onOption('', true) // unselect last
|
this.onOption('', true) // unselect last
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
<header><canvas data-output="agentSampleCanvas"></canvas></header>
|
<header><canvas data-output="agentSampleCanvas"></canvas></header>
|
||||||
<section>
|
<section>
|
||||||
<bz-select label="Agent type..." data-output="agentsSelector"></bz-select>
|
<bz-select label="Agent type..." data-output="agentsSelector"></bz-select>
|
||||||
<bz-toggler></bz-toggler>
|
|
||||||
</section>
|
</section>
|
||||||
</article>
|
</article>
|
||||||
<article eiccard>
|
<article eiccard>
|
||||||
@@ -28,7 +27,7 @@
|
|||||||
</article>
|
</article>
|
||||||
<article eiccard="">
|
<article eiccard="">
|
||||||
<header><h1>Agent properties</h1></header>
|
<header><h1>Agent properties</h1></header>
|
||||||
<section>Props form</section>
|
<section data-output="agentProperties"></section>
|
||||||
</article>
|
</article>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class KeyframeView extends WindozDomContent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fillAgentProperties(agentProps){
|
fillAgentProperties(agentProps){
|
||||||
|
let allFields = []
|
||||||
for(const propName in agentProps){
|
for(const propName in agentProps){
|
||||||
const fieldRow = ui.create(`<div class="cols-2"><label>${propName}</label></div>`)
|
const fieldRow = ui.create(`<div class="cols-2"><label>${propName}</label></div>`)
|
||||||
let component
|
let component
|
||||||
@@ -77,16 +78,18 @@ class KeyframeView extends WindozDomContent {
|
|||||||
break
|
break
|
||||||
case 'list':
|
case 'list':
|
||||||
component = document.createElement('bz-select')
|
component = document.createElement('bz-select')
|
||||||
console.log('choices', agentProps[propName].choices)
|
component.fillOptions( agentProps[propName].choices.map(item => {
|
||||||
// component.fillOptions( agentProps[propName].choices.map(item => {
|
return({ markup: `${item}`, value: item})
|
||||||
// return({ markup: `${item}`, value: item})
|
}))
|
||||||
// }))
|
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
console.warn(`Unknown field type ${agentProps[propName].type}`)
|
console.warn(`Unknown field type ${agentProps[propName].type}`)
|
||||||
}
|
}
|
||||||
fieldRow.append(component)
|
fieldRow.append(component)
|
||||||
|
allFields.push(fieldRow)
|
||||||
}
|
}
|
||||||
|
this.outputs.agentProperties.innerHTML=''
|
||||||
|
this.outputs.agentProperties.append(...allFields)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user