Guest User

Untitled

a guest
May 20th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. /** performs field extraction from the fields of a form */
  2. export const extract_form = (form, opts = {}) => {
  3. let { names = undefined, values = {} } = opts
  4. let nameList = names || Object.values(form.elements).filter(it => it.name).map(it => it.name)
  5. return nameList.reduce((out, name) => {
  6. let input = form[name]
  7. out[name] = (input.type === 'checkbox' || input.type === "radio") ? input.checked : input.value
  8. return out
  9. }, {...values})
  10. }
Add Comment
Please, Sign In to add comment