diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-11-01 18:11:51 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-11-01 18:19:37 +0100 |
| commit | 27777165ac20e604da1a714212ebc4c1f235bb15 (patch) | |
| tree | 7982dc989ce591be79659d45519eda7db9acd597 /src | |
| parent | 36e39ebd496d78ca4e651125b858f53884219ec0 (diff) | |
| download | chawan-27777165ac20e604da1a714212ebc4c1f235bb15.tar.gz | |
dom: fix <select> default state with size=1
Diffstat (limited to 'src')
| -rw-r--r-- | src/html/dom.nim | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index 9652f0dc..94e83bad 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -3660,26 +3660,20 @@ proc resetElement*(element: Element) = input.setInvalid() of TAG_SELECT: let select = HTMLSelectElement(element) - if not select.attrb(satMultiple): - if select.attrul(satSize).get(1) == 1: - var i = 0 - var firstOption: HTMLOptionElement - for option in select.options: - if firstOption == nil: - firstOption = option - if option.selected: - inc i - if i == 0 and firstOption != nil: - firstOption.selected = true - elif i > 2: - # Set the selectedness of all but the last selected option element to - # false. - var j = 0 - for option in select.options: - if j == i: break - if option.selected: - option.selected = false - inc j + var firstOption: HTMLOptionElement = nil + var prevSelected: HTMLOptionElement = nil + let multiple = select.attrb(satMultiple) + for option in select.options: + if firstOption == nil: + firstOption = option + option.selected = option.attrb(satSelected) + if option.selected: + if not multiple and prevSelected != nil: + prevSelected.selected = false + prevSelected = option + if not multiple and select.attrul(satSize).get(1) == 1 and + prevSelected == nil and firstOption != nil: + firstOption.selected = true of TAG_TEXTAREA: let textarea = HTMLTextAreaElement(element) textarea.value = textarea.childTextContent() |