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;
|
||||
}
|
||||
function makeLabel(label, forId) {
|
||||
let ret = document.createElement('label');
|
||||
ret.setAttribute('for', forId);
|
||||
ret.innerHTML = label;
|
||||
return ret;
|
||||
}
|
||||
|
||||
class L3Section {
|
||||
constructor(legend, presetname, ...inputs) {
|
||||
|
@ -111,11 +117,9 @@ class L3MultiSection {
|
|||
this.sections.push(newsection);
|
||||
let nodes = newsection.node();
|
||||
|
||||
let del = document.createElement('button');
|
||||
del.setAttribute('type', 'button');
|
||||
del.addEventListener('click', () => this.#removeSection(newsection, nodes));
|
||||
let del = makeButton('Remove', () => this.#removeSection(newsection, nodes));
|
||||
del.classList.add('del');
|
||||
del.innerHTML = 'Remove';
|
||||
|
||||
nodes.append(del);
|
||||
return nodes;
|
||||
}
|
||||
|
@ -140,10 +144,7 @@ class L3Input {
|
|||
node() {
|
||||
let div = document.createElement('div')
|
||||
if (this.label) {
|
||||
let newLabel = document.createElement('label');
|
||||
newLabel.setAttribute('for', this.id);
|
||||
newLabel.innerHTML = this.label;
|
||||
div.appendChild(newLabel);
|
||||
div.appendChild(makeLabel(this.label, this.id));
|
||||
}
|
||||
|
||||
this.input = makeInput(this.id, this.attrs);
|
||||
|
@ -199,10 +200,7 @@ class L3Select {
|
|||
node() {
|
||||
let div = document.createElement('div')
|
||||
if (this.label) {
|
||||
let newLabel = document.createElement('label');
|
||||
newLabel.setAttribute('for', this.id);
|
||||
newLabel.innerHTML = this.label;
|
||||
div.appendChild(newLabel);
|
||||
div.appendChild(makeLabel(this.label, this.id));
|
||||
}
|
||||
|
||||
this.input = document.createElement('select');
|
||||
|
|
Loading…
Reference in New Issue