getmeformdata

0.4.2 • Public • Published

get-me-form-data

Build Status npm version

Tiny function to get the form data and validate it. https://codesandbox.io/s/vmv90nno45

Install

npm install getmeformdata --save

Usage

const formSpec = {
    name: {
        validator: 'required'
    },
    checkbox: {
      type: 'boolean'
    }
};

function handleOnSubmit(e) {
  e.preventDefault();
  const data = getMeFormData(e.target, formSpec);

  console.log(data); /*eg. {
      data:{
        name: "",
        email: ""
      },
      error: {
          name: "This is required"
      }
    }*/
}

<form onSubmit={handleOnSubmit}>
    <input name="name" />
    <input name="email"/>
    <button>Submit</button>
</form>
}

Publishing

  • npm run build
  • npm version patch -m "message"
  • npm publish --access public

Readme

Keywords

none

Package Sidebar

Install

npm i getmeformdata

Weekly Downloads

22

Version

0.4.2

License

ISC

Unpacked Size

79.7 kB

Total Files

4

Last publish

Collaborators

  • anenth