Archived
Template
1
Fork 0
This repository has been archived on 2024-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
Contour/public/@shoelace-style/shoelace/cdn/chunks/chunk.JUREJPJV.js
2024-01-30 10:59:28 -05:00

41 lines
1 KiB
JavaScript

import {
formCollections
} from "./chunk.NMS6LWK4.js";
// src/utilities/form.ts
function serialize(form) {
const formData = new FormData(form);
const object = {};
formData.forEach((value, key) => {
if (Reflect.has(object, key)) {
const entry = object[key];
if (Array.isArray(entry)) {
entry.push(value);
} else {
object[key] = [object[key], value];
}
} else {
object[key] = value;
}
});
return object;
}
function getFormControls(form) {
const rootNode = form.getRootNode();
const allNodes = [...rootNode.querySelectorAll("*")];
const formControls = [...form.elements];
const collection = formCollections.get(form);
const shoelaceFormControls = collection ? Array.from(collection) : [];
return [...formControls, ...shoelaceFormControls].sort((a, b) => {
if (allNodes.indexOf(a) < allNodes.indexOf(b))
return -1;
if (allNodes.indexOf(a) > allNodes.indexOf(b))
return 1;
return 0;
});
}
export {
serialize,
getFormControls
};