diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-02-20 18:07:18 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-02-20 18:07:18 +0100 |
| commit | 650502ebfac0cad0217249d99cb9433813079072 (patch) | |
| tree | 37460894c67e37f2b0110131786fc641cdf5cf87 /src/html | |
| parent | 24bdc0f1f85192467526ccd7a6df2cdf7de2d0db (diff) | |
| download | chawan-650502ebfac0cad0217249d99cb9433813079072.tar.gz | |
dom: add HTMLOptionsCollection setter
Diffstat (limited to 'src/html')
| -rw-r--r-- | src/html/dom.nim | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 2409388c..b1750d83 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -551,6 +551,7 @@ proc newHTMLElement*(document: Document; tagType: TagType): HTMLElement proc parseColor(element: Element; s: string): ARGBColor proc reflectAttr(element: Element; name: CAtom; value: Option[string]) proc remove*(node: Node) +proc replace*(parent, child, node: Node): Err[DOMException] proc replaceAll(parent: Node; s: sink string) proc attrl(element: Element; name: StaticAtom; value: int32) proc attrul(element: Element; name: StaticAtom; value: uint32) @@ -3243,6 +3244,25 @@ func jsOptions(this: HTMLSelectElement): HTMLOptionsCollection ) return this.cachedOptions +proc setter(ctx: JSContext; this: HTMLOptionsCollection; u: uint32; + value: Option[HTMLOptionElement]): DOMResult[void] {.jssetprop.} = + let element = this.item(u) + if value.isNone: + if element != nil: + element.remove() + return ok() + let value = value.get + let parent = this.root + if element != nil: + ?parent.replace(element, value) + else: + let L = uint32(this.getLength()) + let document = parent.document + for i in L ..< u: + parent.append(document.newHTMLElement(TAG_OPTION)) + parent.append(value) + return ok() + proc length(this: HTMLSelectElement): int {.jsfget.} = return this.jsOptions.getLength() |