0.3.0 • Published 8 years ago

@orange-lion/form-to-json v0.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

form_to_json

form value is to be JSON.

Installation

npm i --save form_to_json

Usage

import formToJSON from 'form_to_json';

const $form = document.querySelector('form');
const json = formToJSON($form);
axios({
  url: '/api/example',
  method: 'POST',
  data: json
})
.then(res => console.log(res))
.catch(err => console.error(err));

What is different from other formToJSON?

It is difficult to get multiple values. This module can easily be obtained by attaching [] such as user_ids [].

For example.

<select name='friend_ids[]'>
  <option value='1'>Jack</option>
  <option value='2' checked>Tom</option>
</select>
<select name='friend_ids[]'>
  <option value='1' checked>Ada</option>
  <option value='2'>Karen</option>
</select>
const json = formToJSON($form);
// => json.friend_ids = ['2', '1']
0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago