Implement CheckField logic

This commit is contained in:
2025-09-21 02:34:26 +02:00
parent 76f8fc1c65
commit 0f8747dce7
3 changed files with 16 additions and 15 deletions

View File

@@ -281,42 +281,37 @@ class SelectField extends FormField {
class CheckField extends FormField {
#input = null;
#container = null;
#thumb = null;
buildField() {
if (!this.#input) {
this.#input = el.div({ class: '-field -check-field' })
this.el.appendChild(this.#input);
dom.append(this.#input, [
this.#container = el.span({ class: '-check-box' }, [
this.#thumb = el.span({ class: '-check-thumb' }, "|||")
el.span({ class: '-check-thumb' }, "|||")
]),
]);
this.#input.addEventListener('click', () => this.toggle());
}
}
toggle() {
if (this.#container.classList.contains('-check-on')) {
this.#container.classList.remove('-check-on');
} else {
this.#container.classList.add('-check-on');
}
this.value = !this.value;
console.log("toggle", this.value);
}
valueUpdated() {
if (!this.#input) return;
// this.#input.innerText = this.value;
if (!!this.value) {
this.#container.classList.add('-check-on');
} else {
this.#container.classList.remove('-check-on');
}
}
getValue() {
// if (this.#input.innerText === '') {
// if (this.options.nullable !== false)
// return null;
// }
return false; // this.#input.innerText;
return this.value;
}
setEditable(state) {
if (state) {
this.#input.classList.add('editable');
} else {
// this.updateValue(this.#input.innerText);
this.#input.classList.remove('editable');
}
}