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) {
// let ret = {};
return Array.from(form.elements).reduce((acc, e) => {
var encodedValue;
switch(e.type) {
case "color":
acc[e.name] = hexToRgb(e.value);
encodedValue = hexToRgb(e.value);
break;
case "number":
acc[e.name] = parseInt(e.value);
encodedValue = parseInt(e.value);
break;
case "checkbox":
acc[e.name] = e.value === "on";
encodedValue = e.value === "on";
break;
default:
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 ret;