Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit 0009e61

Browse files
committed
Updating docs and adding Control.checkbox to FAQs. Fixes #748
1 parent abc959a commit 0009e61

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

docs/api/Control.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ It is a connected component, and will use the `model` prop to connect itself to
2929
The following pre-defined `<Control>`s are available:
3030

3131
- `<Control>` or `<Control.input>` for standard `<input />` controls
32+
- `<Control.custom>` for controls without any default prop mapping
3233
- `<Control.text>` for `<input type="text" />`
3334
- `<Control.textarea>` for `<textarea></textarea>`
3435
- `<Control.radio>` for `<input type="radio" />`

docs/api/Field.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
The `<Field>` component recursively checks its children to see if they can be made into a [`<Control>`](./Control.md). It then maps all of its props over to each created child `<Control>`.
44

5+
If it reaches an unknown component, such as a `<SpecialComponent>`, it will stop recursing and leave the component as-is. In such cases, it is highly recommended to use `<Control>` over `<Field>` whenever possible.
6+
57
Example:
68
```jsx
79
<Field model="user.favoriteColors">

docs/guides/faqs.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,34 @@ You can use `getRef` on `<Field>`, `<Control>`, `<Form>`, or `<LocalForm>` compo
8989
/>
9090
```
9191

92+
### How do I set up single/multiple-value checkboxes?
93+
94+
For a single checkbox that represents a model's boolean `true` or `false` value, you can use `<Control.checkbox>` as expected:
95+
96+
```jsx
97+
// if checked, user.hasPets = true, otherwise false.
98+
<Control.checkbox model="user.hasPets" />
99+
```
100+
101+
For multiple checkboxes that represent multiple possible values for a model, append `[]` to the control to indicate that it is a multi-value model:
102+
103+
```jsx
104+
// if dog and cat are checked, model will be:
105+
// user.pets = ['dog', 'cat']
106+
<Control.checkbox model="user.pets[]" value="dog" />
107+
<Control.checkbox model="user.pets[]" value="cat" />
108+
<Control.checkbox model="user.pets[]" value="goat" />
109+
```
110+
111+
For single or multiple checkboxes that represent boolean keyed values in a model that's an object, use standard dot notation:
112+
113+
```jsx
114+
// if dog and cat are checked, model will be
115+
// user.pets = { dog: true, cat: true, goat: false }
116+
<Control.checkbox model="user.pets.dog" />
117+
<Control.checkbox model="user.pets.cat" />
118+
<Control.checkbox model="user.pets.goat" />
119+
```
120+
92121
### Other Questions and Answers
93122
- https://github.com/davidkpiano/react-redux-form/issues/675#issuecomment-281164930

0 commit comments

Comments
 (0)