@@ -221,8 +221,8 @@ fn collectForm(arena: Allocator, form: *parser.Form, submitter_: ?*parser.Elemen
221221 const tag = try parser .elementHTMLGetTagType (@as (* parser .ElementHTML , @ptrCast (element )));
222222 switch (tag ) {
223223 .input = > {
224- const input_type = try parser .elementGetAttribute (element , "type" ) orelse "" ;
225- if (std .ascii .eqlIgnoreCase (input_type , "image" )) {
224+ const tpe = try parser .elementGetAttribute (element , "type" ) orelse "" ;
225+ if (std .ascii .eqlIgnoreCase (tpe , "image" )) {
226226 if (submitter_name_ ) | submitter_name | {
227227 if (std .mem .eql (u8 , submitter_name , name )) {
228228 try entries .append (arena , .{
@@ -237,11 +237,17 @@ fn collectForm(arena: Allocator, form: *parser.Form, submitter_: ?*parser.Elemen
237237 }
238238 continue ;
239239 }
240- if (std .ascii .eqlIgnoreCase (input_type , "checkbox" ) or std .ascii .eqlIgnoreCase (input_type , "radio" )) {
240+
241+ if (std .ascii .eqlIgnoreCase (tpe , "checkbox" ) or std .ascii .eqlIgnoreCase (tpe , "radio" )) {
241242 if (try parser .inputGetChecked (@ptrCast (element )) == false ) {
242243 continue ;
243244 }
244245 }
246+ if (std .ascii .eqlIgnoreCase (tpe , "submit" )) {
247+ if (submitter_name_ == null or ! std .mem .eql (u8 , submitter_name_ .? , name )) {
248+ continue ;
249+ }
250+ }
245251 const value = (try parser .elementGetAttribute (element , "value" )) orelse "" ;
246252 try entries .append (arena , .{ .key = name , .value = value });
247253 },
@@ -285,6 +291,10 @@ fn collectSelectValues(arena: Allocator, select: *parser.Select, name: []const u
285291 const is_multiple = try parser .selectGetMultiple (select );
286292 if (is_multiple == false ) {
287293 const option = try parser .optionCollectionItem (options , @intCast (selected_index ));
294+
295+ if (try parser .elementGetAttribute (@ptrCast (option ), "disabled" ) != null ) {
296+ return ;
297+ }
288298 const value = try parser .optionGetValue (option );
289299 return entries .append (arena , .{ .key = name , .value = value });
290300 }
@@ -317,7 +327,7 @@ fn getSubmitterName(submitter_: ?*parser.ElementHTML) !?[]const u8 {
317327 .input = > {
318328 const tpe = (try parser .elementGetAttribute (element , "type" )) orelse "" ;
319329 // only an image type can be a sumbitter
320- if (std .ascii .eqlIgnoreCase (tpe , "image" )) {
330+ if (std .ascii .eqlIgnoreCase (tpe , "image" ) or std . ascii . eqlIgnoreCase ( tpe , "submit" ) ) {
321331 return name ;
322332 }
323333 },
@@ -356,8 +366,12 @@ test "Browser.FormData" {
356366 \\
357367 \\ <select name="sel-1"><option>blue<option>red</select>
358368 \\ <select name="sel-2"><option>blue<option value=sel-2-v selected>red</select>
369+ \\ <select name="sel-3"><option disabled>nope1<option>nope2</select>
359370 \\ <select name="mlt-1" multiple><option>water<option>tea</select>
360371 \\ <select name="mlt-2" multiple><option selected>water<option selected>tea<option>coffee</select>
372+ \\ <input type=submit id=s1 name=s1 value=s1-v>
373+ \\ <input type=submit name=s2 value=s2-v>
374+ \\ <input type=image name=i1 value=i1-v>
361375 \\ </form>
362376 });
363377 defer runner .deinit ();
@@ -417,7 +431,9 @@ test "Browser.FormData" {
417431 }, .{});
418432
419433 try runner .testCases (&.{
420- .{ "let f2 = new FormData(document.getElementById('form1'))" , null },
434+ .{ "let form1 = document.getElementById('form1')" , null },
435+ .{ "let submit1 = document.getElementById('s1')" , null },
436+ .{ "let f2 = new FormData(form1, submit1)" , null },
421437 .{ "acc = '';" , null },
422438 .{
423439 \\ for (const entry of f2) {
@@ -437,6 +453,7 @@ test "Browser.FormData" {
437453 \\sel-2=sel-2-v
438454 \\mlt-2=water
439455 \\mlt-2=tea
456+ \\s1=s1-v
440457 },
441458 }, .{});
442459}
0 commit comments