Add rust-form-multi to liveview-dev

This commit is contained in:
Austen Adler 2021-08-22 14:18:16 -04:00
parent 47114718a1
commit 65aa41d780

View File

@ -70,19 +70,38 @@ function hexToRgb(v) {
function getFormData(form) { function getFormData(form) {
// let ret = {}; // let ret = {};
return Array.from(form.elements).reduce((acc, e) => { return Array.from(form.elements).reduce((acc, e) => {
var encodedValue;
switch(e.type) { switch(e.type) {
case "color": case "color":
acc[e.name] = hexToRgb(e.value); encodedValue = hexToRgb(e.value);
break; break;
case "number": case "number":
acc[e.name] = parseInt(e.value); encodedValue = parseInt(e.value);
break; break;
case "checkbox": case "checkbox":
acc[e.name] = e.value === "on"; encodedValue = e.value === "on";
break; break;
default: default:
break; break;
} }
let multiName = e.getAttribute("rust-form-multi");
// This is a multivalue
if (multiName) {
if (acc[multiName]) {
// Push to existing array
acc[multiName].push(encodedValue);
} else {
// This is the first element in the multi-array
acc[multiName] = [encodedValue];
}
} else {
// This is a regular value
acc[e.name] = encodedValue;
}
return acc; return acc;
}, {}); }, {});
// return ret; // return ret;