2.0.1 • Published 7 years ago

conform.js v2.0.1

Weekly downloads
118
License
MIT
Repository
github
Last release
7 years ago

conform.js

A tiny zero-dependency form utility. ~930bytes gzipped.

js-standard-style

Usage

<form id='myForm' action='/submit'>
  <input name='name' />
  <input name='email' type='email' />
  <input name='address[street]' />
  <input name='address[city]' />
  <input name='address[state]' />
  <input name='address[zip]' />
</form>
import conform from 'conform.js'

const form = document.getElementById('myForm')

const myForm = conform(form, {
  email: (node) => {
    return /.+\@.+\..+/.test(node.value)
  },
  'address[*]': (node) => {
    return node.value !== ''
  }
}, (err, formValues) => {
  if (err) {
    console.error(err)
  } else {
    fetch(form.action, {
      method: 'POST',
      credentials: 'include',
      body: JSON.stringify(formValues) // { name: '', email: '', ... } etc
    }).then(res => res.json()).then(res => {
      // success
    })
  }
})

/**
 * Remove form submit listener
 */
myForm.destroy()

MIT License

2.0.1

7 years ago

2.0.0

7 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.4.0

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago