Add return json if option has a name attribute
This commit is contained in:
parent
fcc07d56e2
commit
d3ae471326
|
@ -32,7 +32,16 @@ class SerializerField {
|
||||||
*/
|
*/
|
||||||
serialize() {
|
serialize() {
|
||||||
if (this.field.tagName == "SELECT" && this.field.multiple) {
|
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") {
|
if (this.type == "number" || this.type == "range") {
|
||||||
|
|
|
@ -28,6 +28,11 @@ var testData = []*Person{
|
||||||
Checklist: []string{
|
Checklist: []string{
|
||||||
"Milk",
|
"Milk",
|
||||||
},
|
},
|
||||||
|
JSON: []JSON{
|
||||||
|
{
|
||||||
|
Value: "value",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
&Person{
|
&Person{
|
||||||
|
@ -56,6 +61,11 @@ var testData = []*Person{
|
||||||
Checklist: []string{
|
Checklist: []string{
|
||||||
"Milk",
|
"Milk",
|
||||||
},
|
},
|
||||||
|
JSON: []JSON{
|
||||||
|
{
|
||||||
|
Value: "value",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +104,12 @@ type Person struct {
|
||||||
Languages []Language `json:"languages"`
|
Languages []Language `json:"languages"`
|
||||||
Checklist []string `json:"checklist"`
|
Checklist []string `json:"checklist"`
|
||||||
Animal string `json:"animal"`
|
Animal string `json:"animal"`
|
||||||
|
JSON []JSON `json:"json"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON ...
|
||||||
|
type JSON struct {
|
||||||
|
Value string `json:"key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Language ...
|
// Language ...
|
||||||
|
@ -154,6 +170,9 @@ func isEq(p1, p2 Person) {
|
||||||
for k := range p2.Checklist {
|
for k := range p2.Checklist {
|
||||||
assert(p1.Checklist[k], p2.Checklist[k], "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 {
|
func assert(v, v2 interface{}, ident string) bool {
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
<option selected value="Milk">Milk</option>
|
<option selected value="Milk">Milk</option>
|
||||||
<option value="Eggs">Eggs</option>
|
<option value="Eggs">Eggs</option>
|
||||||
</select>
|
</select>
|
||||||
|
<select multiple name="json">
|
||||||
|
<option selected name="key" value="value">Value</option>
|
||||||
|
</select>
|
||||||
<select name="animal">
|
<select name="animal">
|
||||||
<option value="Dog" selected>Dog</option>
|
<option value="Dog" selected>Dog</option>
|
||||||
<option value="Cat">Cat</option>
|
<option value="Cat">Cat</option>
|
||||||
|
|
Loading…
Reference in New Issue