From 24fc8e940a935f0579cf7bc03bf01e27e5853b80 Mon Sep 17 00:00:00 2001 From: bptato Date: Sun, 17 Jul 2022 22:31:04 +0200 Subject: Implement select element display You can't actually use them yet. But at least they don't flood the screen with options now. --- src/io/buffer.nim | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src/io/buffer.nim') diff --git a/src/io/buffer.nim b/src/io/buffer.nim index 03de9988..0cfcbe18 100644 --- a/src/io/buffer.nim +++ b/src/io/buffer.nim @@ -825,45 +825,57 @@ proc constructEntryList(form: HTMLFormElement, submitter: Element = nil, encodin form.constructingentrylist = true var entrylist: Table[string, string] - for field in form.inputs: + for field in form.controls: if field.findAncestor({TAG_DATALIST}) != nil or field.attrb("disabled") or field.isButton() and Element(field) != submitter: continue - if field.inputType == INPUT_IMAGE: - let name = if field.attr("name") != "": - field.attr("name") & '.' - else: - "" - entrylist[name & 'x'] = $field.xcoord - entrylist[name & 'y'] = $field.ycoord - continue + if field.tagType == TAG_INPUT: + let field = HTMLInputElement(field) + if field.inputType == INPUT_IMAGE: + let name = if field.attr("name") != "": + field.attr("name") & '.' + else: + "" + entrylist[name & 'x'] = $field.xcoord + entrylist[name & 'y'] = $field.ycoord + continue - if field.attr("name") == "": - continue + #TODO custom elements let name = field.attr("name") - #TODO select - if field.inputType in {INPUT_CHECKBOX, INPUT_RADIO}: + + if name == "": + continue + + if field.tagType == TAG_SELECT: + let field = HTMLSelectElement(field) + for option in field.options: + if option.selected or option.disabled: + entrylist[name] = option.value + elif field.tagType == TAG_INPUT and HTMLInputElement(field).inputType in {INPUT_CHECKBOX, INPUT_RADIO}: let value = if field.attr("value") != "": field.attr("value") else: "on" entrylist[name] = value - elif field.inputType == INPUT_FILE: + elif field.tagType == TAG_INPUT and HTMLInputElement(field).inputType == INPUT_FILE: #TODO file discard - elif field.inputType == INPUT_HIDDEN and name.equalsIgnoreCase("_charset_"): + elif field.tagType == TAG_INPUT and HTMLInputElement(field).inputType == INPUT_HIDDEN and name.equalsIgnoreCase("_charset_"): let charset = if encoding != "": encoding else: "UTF-8" entrylist[name] = charset else: - entrylist[name] = field.value + if field.tagType == TAG_INPUT: + entrylist[name] = HTMLInputElement(field).value + else: + assert false if field.tagType == TAG_TEXTAREA or - field.tagType == TAG_INPUT and field.inputType in {INPUT_TEXT, INPUT_SEARCH}: + field.tagType == TAG_INPUT and HTMLInputElement(field).inputType in {INPUT_TEXT, INPUT_SEARCH}: if field.attr("dirname") != "": let dirname = field.attr("dirname") let dir = "ltr" #TODO bidi @@ -1003,7 +1015,6 @@ proc click*(buffer: Buffer): Option[ClickAction] = input.rendered = false buffer.reshape = true if input.form != nil: - eprint "SEARCH", input.value let submitaction = submitForm(input.form, input) return submitaction of INPUT_TEXT, INPUT_PASSWORD: -- cgit 1.4.1-2-gfad0 href='#n8'>8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
href='#n215'>215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265