You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 23, 2022. It is now read-only.
It can also be a function that returns a string model. See [the documentation on tracking](../guides/tracking.md) for more information.
89
89
90
90
<h2id="prop-mapProps"></h2>
91
-
## `mapProps={{...}}`
91
+
## `mapProps={\{...}}`
92
92
_(Object)_: A mapping of control-specific property keys to prop-getter functions that taken in the original props and return the result prop. See [the documentation on custom controls](../guides/custom-controls.md) for more information.
93
93
94
94
Example:
95
95
```jsx
96
96
<Control
97
-
mapProps={{
97
+
mapProps={\{
98
98
customChange: (props) =>props.change,
99
99
}}
100
100
model="..."
@@ -118,15 +118,15 @@ You can also specify `updateOn={['change', 'blur']}` as an array of one or more
118
118
- Use the `changeAction` prop if you want to dispatch custom actions along with the `actions.change(...)` action.
119
119
120
120
<h2id="prop-validators"></h2>
121
-
## `validators={{...}}`
121
+
## `validators={\{...}}`
122
122
_(Object)_: A map where the keys are validation keys, and the values are the corresponding functions that determine the validity of each key, given the model's value.
123
123
124
124
For example, this control validates that a username exists and is longer than 4 characters:
@@ -158,7 +158,7 @@ _(String | Array)_: A string/array of strings specifying when validation should
158
158
- To avoid displaying error messages on load (as controls might be invalid), use the `.pristine` property of the control when conditionally showing error messages, or use the `<Errors>` component.
159
159
160
160
<h2id="prop-asyncValidators"></h2>
161
-
## `asyncValidators={{...}}`
161
+
## `asyncValidators={\{...}}`
162
162
_(Object)_: A map where the keys are validation keys, and the values are the corresponding functions that (asynchronously) determine the validity of each key, given the model's value.
163
163
164
164
Each async validator function is called with 2 arguments:
@@ -172,7 +172,7 @@ For example, this control validates that a username is available via a promise:
172
172
importisAvailablefrom'../path/to/is-available';
173
173
174
174
<Control.text model="user.username"
175
-
asyncValidators={{
175
+
asyncValidators={\{
176
176
isAvailable: (value, done) => {
177
177
isAvailable(value)
178
178
.then((result) =>done(result));
@@ -191,7 +191,7 @@ _(String | Array)_: A string/array of strings specifying when async validation s
191
191
-`"focus"` - validate on the `onFocus` event handler
192
192
193
193
<h2id="prop-errors"></h2>
194
-
## `errors={{...}}`
194
+
## `errors={\{...}}`
195
195
_(Object)_: A map where the keys are error keys, and the values are the corresponding error validator functions that determine the invalidity of each key, given the model's value.
196
196
197
197
An **error validator** is a function that returns `true` or a truthy value (such as a string) if invalid, and `false` if valid.
@@ -201,7 +201,7 @@ For example, this control validates that a username exists and is longer than 4
201
201
```jsx
202
202
<Control.text
203
203
model="user.username"
204
-
errors={{
204
+
errors={\{
205
205
isEmpty: (val) =>!val.length,
206
206
tooLong: (val) =>val.length>16,
207
207
}}
@@ -270,7 +270,7 @@ function changeAndSubmit(model, value) {
270
270
- Since `changeAction` expects an action creator and `redux-thunk` is used, you can asynchronously dispatch actions (like the example above).
271
271
272
272
<h2id="prop-controlProps"></h2>
273
-
## `controlProps={{...}}`
273
+
## `controlProps={\{...}}`
274
274
_(Object)_: A mapping of control-specific props that will be applied directly to the rendered control. In some cases, this can be a safer way of applying props, especially if there are naming conflicts between `<Control>`-specific props (such as `"model"`) and props that need to go on the rendered control (e.g., `<input {...props} />`).
275
275
276
276
The normal behavior is that any extraneous props on `<Control>` that are not part of `Control.propTypes` (which are documented here) will be given to the rendered input.
@@ -282,7 +282,7 @@ Example:
282
282
<Control.text
283
283
model="..."
284
284
component={CustomInput}
285
-
controlProps={{errors:'errors for CustomInput'}}
285
+
controlProps={\{errors:'errors for CustomInput'}}
286
286
/>
287
287
```
288
288
@@ -325,7 +325,7 @@ However, in `<Control>`, it can be a boolean, or a function, string, or object a
325
325
// Disable the submit button when the form is invalid
326
326
<Control.button
327
327
model="user"
328
-
disabled={{ valid:false }}
328
+
disabled={\{ valid:false }}
329
329
>
330
330
Submit!
331
331
</Control.button>
@@ -334,7 +334,7 @@ However, in `<Control>`, it can be a boolean, or a function, string, or object a
334
334
For example:
335
335
-`disabled={true}` or `disabled={false}` will disable or enable the control respectively, as will any other primitive value, such as `undefined`, `null`, or a number
336
336
-`disabled="touched"` will disable if the field is `touched` (works with any property on the field)
337
-
-`disabled={{ valid: false, touched: true }}` will disable if the field is both `touched` and not `valid`
337
+
-`disabled={\{ valid: false, touched: true }}` will disable if the field is both `touched` and not `valid`
338
338
-`disabled={(fieldValue) => !fieldValue.valid}` will call the function provided with the `fieldValue` to determine its `disabled` state.
339
339
340
340
(since: version 1.3.0)
@@ -360,7 +360,7 @@ _(Boolean)_: Signifies that the field state (validation, etc.) should not persis
Copy file name to clipboardExpand all lines: docs/api/Errors.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,12 @@ The `<Errors />` component provides a handy way of displaying form errors for a
9
9
<Control.text
10
10
type="email"
11
11
model="user.email"
12
-
validators={{ isEmail, isRequired }}
12
+
validators={\{ isEmail, isRequired }}
13
13
/>
14
14
15
15
<Errors
16
16
model="user.email"
17
-
messages={{
17
+
messages={\{
18
18
isRequired:'Please provide an email address.',
19
19
isEmail: (val) =>`${val} is not a valid email.`,
20
20
}}
@@ -48,13 +48,13 @@ _(String | Function)_: the string representation of the model path to show the e
48
48
```jsx
49
49
<Errors
50
50
model="user"
51
-
messages={{
51
+
messages={\{
52
52
passwordsMatch:'Passwords do not match.',
53
53
}}
54
54
/>
55
55
```
56
56
57
-
## `messages={{...}}`
57
+
## `messages={\{...}}`
58
58
59
59
_(Object)_: a plain object mapping where:
60
60
- the keys are error keys (such as `"required"`)
@@ -67,7 +67,7 @@ If the message value is a function, it will be called with the model value.
67
67
```jsx
68
68
<Errors
69
69
model="user.email"
70
-
messages={{
70
+
messages={\{
71
71
required:'Please enter an email address.',
72
72
length:'The email address is too long.',
73
73
invalid: (val) =>`${val} is not a valid email address.',
@@ -78,19 +78,19 @@ If the message value is a function, it will be called with the model value.
78
78
### Notes
79
79
- The `messages` prop is a great place to keep custom error messages that can vary based on the location in the UI, instead of hardcoding error messages in validation fuctions.
80
80
- If a message is _not_ provided for an error key, the message will default to the key value in the control's `.errors` property.
81
-
- This means if you're using `actions.setErrors` or the `errors={{...}}` prop in`<Control>` or `<Field>` to set error messages, they will automatically be shown in`<Errors />`.
81
+
- This means if you're using `actions.setErrors` or the `errors={\{...}}` prop in`<Control>` or `<Field>` to set error messages, they will automatically be shown in`<Errors />`.
82
82
83
83
## `show={...}`
84
84
85
85
_(Any)_: The `show` prop determines when error messages should be shown, based on the model's field state (determined by the form reducer).
86
86
87
-
It can be a boolean, or a function, string, or object as a [Lodash iteratee](https://lodash.com/docs#iteratee).
87
+
It can be a boolean, or a function, string, or object as a [Lodash iteratee](https://lodash.com/docs#iteratee).
88
88
89
89
90
90
### Examples
91
91
- `show={true}` will always show the errors if they exist
92
92
- `show={(field) => field.touched && !field.focus}` will show errors if the model's field is touched and not focused
93
-
-`show={{touched: true, focus: false}}` is the same as above
93
+
-`show={\{touched: true, focus: false}}` is the same as above
94
94
-`show="touched"` will show errors if the model's field is touched
95
95
96
96
### Notes
@@ -112,7 +112,7 @@ _(String | Function | Element)_: The `wrapper` component, which is the component
112
112
113
113
_(String | Function | Element)_: The `component`, which is the component for each error message, can be configured using this prop. Default: `"span"`.
114
114
115
-
### Examples
115
+
### Examples
116
116
- `component="li"` will wrap all errors in a `<li>`
117
117
- `component={(props) => <div className="error">{props.children}</div>}` will render the error message in the specified functional component, with these props:
You can also use [partial models](../guides/partial-models.md) for `<Control>`, `<Field>`, `<Fieldset>`, and `<Errors>` components inside of `<Form>` - they will be resolved to the form's model.
51
51
52
-
## `validators={{...}}`
52
+
## `validators={\{...}}`
53
53
_(Object)_: An object representing the validators for the fields inside the form, where:
54
54
55
55
- the **keys** are the field model names (e.g. `'email'` for `user.email`)
@@ -65,15 +65,15 @@ Validation will occur on _any field model change_ by default, and only the valid
65
65
- Specifying validators on the form is usually sufficient - you don't need to put validators on the `<Field>` or `<Control>` for most use cases.
66
66
- If you need validators to run on submit, this is the place to put them.
67
67
68
-
## `errors={{...}}`
68
+
## `errors={\{...}}`
69
69
_(Object)_: An object representing the error validators for the fields inside the form, where:
70
70
71
71
- the **keys** are the field model names (e.g. `'email'` for `user.email`)
72
72
- the **values** are error validator(s) for the field model. They can be:
73
73
- an error validator function, which receives the field model value, or
74
74
- an error validator object, with validation keys and error validator functions as values, also receiving the field model value.
75
75
76
-
Its behavior is identical to the `validators={{...}}` prop, with the exception that an error validator that returns anything truthy is interpreted as an _error_. See [the validation guide](../guides/validation.md) for more info.
76
+
Its behavior is identical to the `validators={\{...}}` prop, with the exception that an error validator that returns anything truthy is interpreted as an _error_. See [the validation guide](../guides/validation.md) for more info.
77
77
78
78
## `validateOn="..."`
79
79
_(String)_: A string that indicates when `validators` or `errors` (for error validators) should run.
@@ -124,7 +124,7 @@ class MyForm extends React.Component {
124
124
return (
125
125
<Form
126
126
model="user"
127
-
validators={{...}}
127
+
validators={\{...}}
128
128
onSubmit={ (user) =>this.handleSubmit(user) }
129
129
>
130
130
<Control type="email" model=".email"/>
@@ -168,7 +168,7 @@ class MyForm extends React.Component {
Some custom controls won't have prop keys that match up exactly with the standard event handler props, such as `onChangeText` in React Native's `<TextInput>` component corresponding to `onChange`. You can specify a prop mapping in the `mapProps={{...}}` prop to specify the mapping:
127
+
Some custom controls won't have prop keys that match up exactly with the standard event handler props, such as `onChangeText` in React Native's `<TextInput>` component corresponding to `onChange`. You can specify a prop mapping in the `mapProps={\{...}}` prop to specify the mapping:
0 commit comments