From 0f8747dce7b596013ed7584282980b3f810b54fe Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sun, 21 Sep 2025 02:34:26 +0200 Subject: [PATCH] Implement CheckField logic --- dialog.css | 4 ++++ jsonform.css | 4 +++- jsonform.js | 23 +++++++++-------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/dialog.css b/dialog.css index f04cf01..a618ba7 100644 --- a/dialog.css +++ b/dialog.css @@ -95,6 +95,10 @@ margin: 0px 0.25rem; background: var(--jsl-dialog-button-normal); box-shadow: inset -1px -1px 1px 0px #bbb, inset 1px 1px 1px 0px #fff; + cursor: pointer; + &.disabled { + cursor: default; + } &.default-action { outline: solid 1px #666; } diff --git a/jsonform.css b/jsonform.css index 6b44be0..67029fb 100644 --- a/jsonform.css +++ b/jsonform.css @@ -78,12 +78,14 @@ padding-left: 0em; padding-right: 1rem; border-radius: 0.25rem; - background-color: #929292; + border: solid 1px #444; + background: linear-gradient(to bottom, rgba(0,0,0,0.2), rgba(0,0,0,0)), #929292; color: #dddddd; .-check-thumb { border-radius: 0.25rem; background-color: #444; padding: 0.25rem 0.5rem; + box-shadow: 0px 0px 5px rgba(0,0,0,0.25); } &.-check-on { padding-left: 1em; diff --git a/jsonform.js b/jsonform.js index 8d83e10..e83c6e3 100644 --- a/jsonform.js +++ b/jsonform.js @@ -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'); } }