debian-mirror-gitlab/app/assets/javascripts/lib/utils/forms.js
2019-10-12 21:52:04 +05:30

12 lines
417 B
JavaScript

export const serializeFormEntries = entries =>
entries.reduce((acc, { name, value }) => Object.assign(acc, { [name]: value }), {});
export const serializeForm = form => {
const fdata = new FormData(form);
const entries = Array.from(fdata.keys()).map(key => {
const val = fdata.getAll(key);
return { name: key, value: val.length === 1 ? val[0] : val };
});
return serializeFormEntries(entries);
};