factor out input label creation
This commit is contained in:
parent
8f22292c02
commit
049dc31928
22
l3config.js
22
l3config.js
|
@ -30,6 +30,12 @@ function makeInput(id, attrs) {
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
function makeLabel(label, forId) {
|
||||||
|
let ret = document.createElement('label');
|
||||||
|
ret.setAttribute('for', forId);
|
||||||
|
ret.innerHTML = label;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
class L3Section {
|
class L3Section {
|
||||||
constructor(legend, presetname, ...inputs) {
|
constructor(legend, presetname, ...inputs) {
|
||||||
|
@ -111,11 +117,9 @@ class L3MultiSection {
|
||||||
this.sections.push(newsection);
|
this.sections.push(newsection);
|
||||||
let nodes = newsection.node();
|
let nodes = newsection.node();
|
||||||
|
|
||||||
let del = document.createElement('button');
|
let del = makeButton('Remove', () => this.#removeSection(newsection, nodes));
|
||||||
del.setAttribute('type', 'button');
|
|
||||||
del.addEventListener('click', () => this.#removeSection(newsection, nodes));
|
|
||||||
del.classList.add('del');
|
del.classList.add('del');
|
||||||
del.innerHTML = 'Remove';
|
|
||||||
nodes.append(del);
|
nodes.append(del);
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
@ -140,10 +144,7 @@ class L3Input {
|
||||||
node() {
|
node() {
|
||||||
let div = document.createElement('div')
|
let div = document.createElement('div')
|
||||||
if (this.label) {
|
if (this.label) {
|
||||||
let newLabel = document.createElement('label');
|
div.appendChild(makeLabel(this.label, this.id));
|
||||||
newLabel.setAttribute('for', this.id);
|
|
||||||
newLabel.innerHTML = this.label;
|
|
||||||
div.appendChild(newLabel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.input = makeInput(this.id, this.attrs);
|
this.input = makeInput(this.id, this.attrs);
|
||||||
|
@ -199,10 +200,7 @@ class L3Select {
|
||||||
node() {
|
node() {
|
||||||
let div = document.createElement('div')
|
let div = document.createElement('div')
|
||||||
if (this.label) {
|
if (this.label) {
|
||||||
let newLabel = document.createElement('label');
|
div.appendChild(makeLabel(this.label, this.id));
|
||||||
newLabel.setAttribute('for', this.id);
|
|
||||||
newLabel.innerHTML = this.label;
|
|
||||||
div.appendChild(newLabel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.input = document.createElement('select');
|
this.input = document.createElement('select');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user