surf icon indicating copy to clipboard operation
surf copied to clipboard

Check for radio input fails

Open klokare opened this issue 6 years ago • 1 comments

The code in serializeForm only adds radio fields that are checked but this code also does not properly identify the checked attribute properly:

if c, found := s.Attr("checked"); found && strings.ToLower(c) == "checked" {
    fields.Add(name, val)
}

s.Attr("checked") returns an empty string even if the element is found because goquery.Selection.Attr returns the value not the name of the attribute and checked attributes have no value, they are either present or not. So c will not equal "checked". Since only 1 radio input for a given name can be checked, the above code could be rewritten as

if c, found := s.Attr("checked"); found {
    fields.Add(name, val)
}

If you believe I am correct about this and feel like it is a good solution, I am happy to put together a pull request.

klokare avatar Oct 08 '18 18:10 klokare

HTML 4 & 5 will accept the condensed version <input type="radio" value="2" checked> but XHTML will not. So the change would need to support both versions.

<input type="radio" value="2" checked> and <input type="radio" value="2" checked="checked">

A fix was just done for the <select> tag in #108. Looks like we need to extend this to <input> tag for radio and checkbox.

jtwatson avatar Oct 12 '18 17:10 jtwatson