OpenAuth_server/FrontendLegacy/shared/formdata.js

19 lines
505 B
JavaScript
Raw Permalink Normal View History

2018-11-06 19:48:50 +00:00
export default function getFormData(element) {
let data = {};
2020-08-07 14:16:39 +00:00
if (
element.name !== undefined &&
element.name !== null &&
element.name !== ""
) {
2018-11-06 19:48:50 +00:00
if (typeof element.name === "string") {
if (element.type === "checkbox") data[element.name] = element.checked;
else data[element.name] = element.value;
}
}
2020-08-07 14:16:39 +00:00
element.childNodes.forEach((child) => {
2018-11-06 19:48:50 +00:00
let res = getFormData(child);
data = Object.assign(data, res);
2020-08-07 14:16:39 +00:00
});
2018-11-06 19:48:50 +00:00
return data;
2020-08-07 14:16:39 +00:00
}