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

View File

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