Add return json if option has a name attribute

This commit is contained in:
Crow Crowcrow 2018-05-15 11:25:22 +02:00
parent fcc07d56e2
commit d3ae471326
Signed by: Crow
GPG Key ID: 45A8E203AF859FD8
3 changed files with 32 additions and 1 deletions

View File

@ -32,7 +32,16 @@ class SerializerField {
*/
serialize() {
if (this.field.tagName == "SELECT" && this.field.multiple) {
return Array.apply(null, this.field.options).filter(o => o.selected).map(o => o.value)
return Array.apply(null, this.field.options).filter(o => o.selected).map(o => {
let name = o.getAttribute("name") || false
if(!name){
return o.value
}
let v = {}
v[name] = o.value
return v
})
}
if (this.type == "number" || this.type == "range") {

View File

@ -28,6 +28,11 @@ var testData = []*Person{
Checklist: []string{
"Milk",
},
JSON: []JSON{
{
Value: "value",
},
},
},
nil,
&Person{
@ -56,6 +61,11 @@ var testData = []*Person{
Checklist: []string{
"Milk",
},
JSON: []JSON{
{
Value: "value",
},
},
},
}
@ -94,6 +104,12 @@ type Person struct {
Languages []Language `json:"languages"`
Checklist []string `json:"checklist"`
Animal string `json:"animal"`
JSON []JSON `json:"json"`
}
// JSON ...
type JSON struct {
Value string `json:"key"`
}
// Language ...
@ -154,6 +170,9 @@ func isEq(p1, p2 Person) {
for k := range p2.Checklist {
assert(p1.Checklist[k], p2.Checklist[k], "Checklist")
}
for k := range p2.JSON {
assert(p1.JSON[k], p2.JSON[k], "JSON")
}
}
func assert(v, v2 interface{}, ident string) bool {

View File

@ -37,6 +37,9 @@
<option selected value="Milk">Milk</option>
<option value="Eggs">Eggs</option>
</select>
<select multiple name="json">
<option selected name="key" value="value">Value</option>
</select>
<select name="animal">
<option value="Dog" selected>Dog</option>
<option value="Cat">Cat</option>