Skip to content

Commit 383b0b0

Browse files
committed
Updated README with array notation + fixed typo.
1 parent a7c5948 commit 383b0b0

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,30 @@ class Form extends React.Component {
7474
7575
## Documentation
7676
77-
**React-input-handler** a single function which accept an event as unique argument.
77+
**React-input-handler** is a single function which accept an unique argument: an event.
7878
7979
The objective is simple: handle input changes and persist them into the component's state.
8080
81+
### Array notation
82+
83+
By default, **react-input-handler** handles checkbox as boolean value. Sometimes, we may want two or more checkboxes to be handled as an array sharing the same `name` attribute. To achieve this we have to suffix the `name` attribute with `[]`. For example:
84+
85+
**Before:**
86+
87+
```js
88+
<input type="checkbox" name="numbers" value="1" onChange={ReactInputHandler.bind(this)} />
89+
<input type="checkbox" name="numbers" value="2" onChange={ReactInputHandler.bind(this)} />
90+
<input type="checkbox" name="numbers" value="3" onChange={ReactInputHandler.bind(this)} />
91+
```
92+
93+
**After:**
94+
95+
```js
96+
<input type="checkbox" name="numbers[]" value="1" onChange={ReactInputHandler.bind(this)} />
97+
<input type="checkbox" name="numbers[]" value="2" onChange={ReactInputHandler.bind(this)} />
98+
<input type="checkbox" name="numbers[]" value="3" onChange={ReactInputHandler.bind(this)} />
99+
```
100+
81101
## Development
82102
83103
1. Clone and fork this repo.

0 commit comments

Comments
 (0)