Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** performs field extraction from the fields of a form */
- export const extract_form = (form, opts = {}) => {
- let { names = undefined, values = {} } = opts
- let nameList = names || Object.values(form.elements).filter(it => it.name).map(it => it.name)
- return nameList.reduce((out, name) => {
- let input = form[name]
- out[name] = (input.type === 'checkbox' || input.type === "radio") ? input.checked : input.value
- return out
- }, {...values})
- }
Add Comment
Please, Sign In to add comment