diff options
author | bptato <nincsnevem662@gmail.com> | 2025-01-03 22:00:42 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2025-01-03 22:00:42 +0100 |
commit | 5efc2958bb5664588d5d2c5406034facdc689f56 (patch) | |
tree | 5864ba7b8af07429717010d370a0587aad4ed142 /src | |
parent | d64e65a278ba0beeac46c2c2d0465dae4a496acc (diff) | |
download | chawan-5efc2958bb5664588d5d2c5406034facdc689f56.tar.gz |
dom: add option value setter, input checked setter
Diffstat (limited to 'src')
-rw-r--r-- | src/html/dom.nim | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index c326bbad..26ffc2c9 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -2609,7 +2609,7 @@ proc sheets*(document: Document): seq[CSSStylesheet] = func checked*(input: HTMLInputElement): bool {.inline.} = return input.internalChecked -proc setChecked*(input: HTMLInputElement; b: bool) {.inline.} = +proc setChecked*(input: HTMLInputElement; b: bool) {.jsfset: "checked".} = input.invalidDeps.incl(dtChecked) input.internalChecked = b @@ -3061,6 +3061,31 @@ proc showPicker(this: HTMLSelectElement): Err[DOMException] {.jsfunc.} = #TODO add, remove +# <option> +# https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-disabled +func isDisabled*(option: HTMLOptionElement): bool = + if option.parentElement of HTMLOptGroupElement and + option.parentElement.attrb(satDisabled): + return true + return option.attrb(satDisabled) + +func text(option: HTMLOptionElement): string {.jsfget.} = + var s = "" + for child in option.descendants: + let parent = child.parentElement + if child of Text and (parent.tagTypeNoNS != TAG_SCRIPT or + parent.namespace notin {Namespace.HTML, Namespace.SVG}): + s &= Text(child).data + return s.stripAndCollapse() + +func value*(option: HTMLOptionElement): string {.jsfget.} = + if option.attrb(satValue): + return option.attr(satValue) + return option.text + +proc setValue(option: HTMLOptionElement; s: string) {.jsfset: "value".} = + option.attr(satValue, s) + # <button> func jsForm(this: HTMLButtonElement): HTMLFormElement {.jsfget: "form".} = return this.form @@ -3294,27 +3319,6 @@ func title*(document: Document): string {.jsfget.} = return title.childTextContent.stripAndCollapse() return "" -# https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-disabled -func isDisabled*(option: HTMLOptionElement): bool = - if option.parentElement of HTMLOptGroupElement and - option.parentElement.attrb(satDisabled): - return true - return option.attrb(satDisabled) - -func text(option: HTMLOptionElement): string {.jsfget.} = - var s = "" - for child in option.descendants: - let parent = child.parentElement - if child of Text and (parent.tagTypeNoNS != TAG_SCRIPT or - parent.namespace notin {Namespace.HTML, Namespace.SVG}): - s &= Text(child).data - return s.stripAndCollapse() - -func value*(option: HTMLOptionElement): string {.jsfget.} = - if option.attrb(satValue): - return option.attr(satValue) - return option.text - proc invalidateCollections(node: Node) = for id in node.liveCollections: node.document.invalidCollections.incl(id) |