Add radio support

This commit is contained in:
Crow Crowcrow 2018-05-03 16:03:34 +02:00
parent d98ebab393
commit fcc07d56e2
Signed by: Crow
GPG Key ID: 45A8E203AF859FD8
1 changed files with 28 additions and 0 deletions

View File

@ -48,6 +48,12 @@ class SerializerField {
return new Date(this.field.value);
}
if (this.type == "radio") {
if (!this.field.checked) {
return null
}
}
if (this.type == "checkbox") {
let checked = this.field.checked;
if (this.field.hasAttribute("string")) {
@ -103,6 +109,7 @@ class Serializer {
}
let isArray = fieldName.match(/^\[(\d*)\]/);
let isRadio = f.type == "radio";
fieldName = fieldName.replace(/^\[\d*\]/, "");
@ -131,6 +138,12 @@ class Serializer {
} else {
this._fields.get(fieldName).push(field);
}
} else if (isRadio) {
if (!this._fields.has(fieldName)) {
this._fields.set(fieldName, []);
}
this._fields.get(fieldName).push(field);
} else {
this._fields.set(fieldName, field);
}
@ -168,6 +181,21 @@ class Serializer {
json = [];
}
for (let key in f) {
if (f[key].type == "radio") {
json = {}
let d = f[key].serialize();
if (d !== null) {
if (k == "") {
json = d;
break;
}
json[k] = d;
break;
}
continue
}
if (f[key]) {
let d = f[key].serialize();
if (d == null) {