form-extract

1.0.0 • Public • Published

Table of Contents

Extract values from a form element into an object


Built with ❤︎ by tiaanduplessis and contributors

Table of Contents

Table of Contents
  • Install
  • Usage
  • Contribute
  • License
  • Install

    With package manager:

    $ npm install form-extract
    # OR 
    $ yarn add form-extract

    With CDN:

    <script src="https://cdn.rawgit.com/tiaanduplessis/form-extract/master/dist/form-extract.min.js"></script>
    <!-- Or -->
    <script src="https://unpkg.com/form-extract/dist/form-extract.min.js"></script>

    Usage

    Say you have a HTML form:

    <form class="foo">
      <input name="name" value="Tiaan">
      <input name="surname" value="du Plessis">
      <input name="country" value="South Africa">
      <input name="city" value="Cape Town">
      <input name="gender" type="radio" value="m" checked>
      <input name="gender" type="radio" value="f">
      <input name="languages" type="checkbox" value="javascript" checked>
      <input name="languages" type="checkbox" value="scala">
      <input name="languages" type="checkbox" value="go" checked>
      <input type="submit" value="Submit">
    </form>

    This can then be extracted to a object:

    import formExtract from 'form-extract'
     
    formExtract('.foo') // formExtract(document.querySelector('.foo')) also works
    // {
    //   city: "Cape Town",
    //   country: "South Africa",
    //   gender: "m",
    //   languages: ["javascript", "go"],
    //   name: "Tiaan",
    //   surname: "du Plessis"
    // }
     

    Contributing

    Contributions are welcome!

    1. Fork it.
    2. Create your feature branch: git checkout -b my-new-feature
    3. Commit your changes: git commit -am 'Add some feature'
    4. Push to the branch: git push origin my-new-feature
    5. Submit a pull request :D

    Or open up a issue.

    License

    Licensed under the MIT License.

    Readme

    Keywords

    none

    Package Sidebar

    Install

    npm i form-extract

    Weekly Downloads

    0

    Version

    1.0.0

    License

    MIT

    Last publish

    Collaborators

    • tiaanduplessis