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

Commit

Permalink
Merge branch 'master' of ssh://github.com/davidkpiano/react-redux-form
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkpiano committed Nov 18, 2017
2 parents eb18aa8 + 6c00ea4 commit 0d0f51b
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 123 deletions.
85 changes: 42 additions & 43 deletions docs/api/Control.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{% raw %}
# Control Component

**Prop Types**
- [`model` (required)](#prop-model)
- [`mapProps`](#prop-mapProps)
- [`updateOn`](#prop-updateOn)
- [`defaultValue`](#prop-defaultValue)
- [`debounce`](#prop-debounce)
- [`validators`](#prop-validators)
- [`validateOn`](#prop-validateOn)
- [`asyncValidators`](#prop-asyncValidators)
- [`asyncValidateOn`](#prop-asyncValidateOn)
- [`errors`](#prop-errors)
- [`parser`](#prop-parser)
- [`changeAction`](#prop-changeAction)
- [`controlProps`](#prop-controlProps)
- [`component`](#prop-component)
- [`ignore`](#prop-ignore)
- [`disabled`](#prop-disabled)
- [`getRef`](#prop-getRef)
- [`persist`](#prop-persist)
- [`getValue`](#prop-getValue)
- [`isToggle`](#prop-isToggle)
- [`model` (required)](#model-required)
- [`mapProps`](#mapprops)
- [`updateOn`](#updateon)
- [`defaultValue`](#defaultvalue)
- [`validators`](#validators)
- [`debounce`](#debounce)
- [`validateOn`](#validateon)
- [`asyncValidators`](#asyncvalidators)
- [`asyncValidateOn`](#asyncvalidateon)
- [`errors`](#errors)
- [`parser`](#parser--)
- [`changeAction`](#changeaction--)
- [`controlProps`](#controlprops)
- [`component`](#component)
- [`ignore`](#ignore)
- [`disabled`](#disabled)
- [`getRef`](#getref--)
- [`persist`](#persistfalse)
- [`getValue`](#getvalueevent-props--)
- [`isToggle`](#istogglefalse)
- [`withFieldValue`](#withfieldvaluefalse)

## `<Control>`

Expand Down Expand Up @@ -76,7 +76,7 @@ export default App; // no need to connect

# Prop Types

## `model="..."` (required) {#prop-model}
## `model="..."` (required)

_(String | Function)_: The string representing the model value in the store.
```jsx
Expand All @@ -92,7 +92,7 @@ export default createStore(combineForms({

It can also be a function that returns a string model. See [the documentation on tracking](../guides/tracking.md) for more information.

## `mapProps={{...}}` {#prop-mapProps}
## `mapProps={{...}}`
_(Object | Function)_: A custom mapping from props provided by `Control` to props received by the component. Can be:

- An object, where each value is a function from original props to corresponding value in result props.
Expand All @@ -114,7 +114,7 @@ Examples:

See [the documentation on custom controls](../guides/custom-controls.md) for more information.

## `updateOn="..."` {#prop-updateOn}
## `updateOn="..."`
_(String | Array)_: A string/array of strings specifying when the component should dispatch a `change(...)` action, with one of these values:

- `"change"` - will dispatch in `onChange`
Expand All @@ -128,13 +128,13 @@ You can also specify `updateOn={['change', 'blur']}` as an array of one or more
### Notes
- Use the `changeAction` prop if you want to dispatch custom actions along with the `actions.change(...)` action.

## `defaultValue="..."` {#prop-defaultValue}
## `defaultValue="..."`
_(Any)_: Sets the default value for the control. `boolean` for checkboxes, `string` for text input/textarea etc.

### Notes
- https://github.com/davidkpiano/react-redux-form/issues/631

## `validators={{...}}` {#prop-validators}
## `validators={{...}}`
_(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.

For example, this control validates that a username exists and is longer than 4 characters:
Expand Down Expand Up @@ -162,10 +162,10 @@ const length = (val) => val.length > 8;
/>
```

## `debounce={...}` {#prop-debounce}
## `debounce={...}`
_(Number)_: The time in milliseconds, by which the change action will be debounced.

## `validateOn="..."` {#prop-validateOn}
## `validateOn="..."`
_(String | Array)_: A string/array of strings specifying when validation should occur. By default, validation happens with whatever `updateOn` is set to. The `validateOn` property can have these values:
- `"change"` - validate on the `onChange` event handler
- `"blur"` - validate on the `onBlur` event handler
Expand All @@ -175,7 +175,7 @@ _(String | Array)_: A string/array of strings specifying when validation should
- Validation will always occur **on load**; i.e., when the component is mounted. This is to ensure an accurate validation state for a new form.
- 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.

## `asyncValidators={{...}}` {#prop-asyncValidators}
## `asyncValidators={{...}}`
_(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.

Each async validator function is called with 2 arguments:
Expand All @@ -200,13 +200,13 @@ import isAvailable from '../path/to/is-available';
### Notes
- Async validators will run on `blur`, unless you specify otherwise in the `asyncValidateOn="..."` prop.

## `asyncValidateOn="..."` {#prop-asyncValidateOn}
## `asyncValidateOn="..."`
_(String | Array)_: A string/array of strings specifying when async validation should occur. By default, validation happens on `"blur"`. The `asyncValidateOn` property can have these values:
- `"change"` - validate on the `onChange` event handler
- `"blur"` (default) - validate on the `onBlur` event handler
- `"focus"` - validate on the `onFocus` event handler

## `errors={{...}}` {#prop-errors}
## `errors={{...}}`
_(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.

An **error validator** is a function that returns `true` or a truthy value (such as a string) if invalid, and `false` if valid.
Expand All @@ -223,7 +223,7 @@ For example, this control validates that a username exists and is longer than 4
/>
```

## `parser={() => ...}` {#prop-parser}
## `parser={() => ...}`
_(Function)_: A function that _parses_ the view value of the control before it is changed. It takes in one argument:
- `value` - the view value that represents the _next_ model value

Expand All @@ -240,7 +240,7 @@ function toAge(value) {
>
```

## `changeAction={() => ...}` {#prop-changeAction}
## `changeAction={() => ...}`
An action creator (function) that specifies which action the `<Control>` component should use when dispatching a change to the model. For example, this action is similar to:

- `actions.change(model, value)` for text input controls
Expand Down Expand Up @@ -281,7 +281,7 @@ function changeAndSubmit(model, value) {
- Use `changeAction` to do any other custom actions whenever your value is to change.
- Since `changeAction` expects an action creator and `redux-thunk` is used, you can asynchronously dispatch actions (like the example above).

## `controlProps={{...}}` {#prop-controlProps}
## `controlProps={{...}}`
_(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} />`).

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.
Expand All @@ -297,7 +297,7 @@ Example:
/>
```

## `component={...}` {#prop-component}
## `component={...}`
_(Function | String | Node)_: A custom component can be passed into the `component={...}` prop, and standard control props and event handlers (such as `onChange`, `onBlur`, `onFocus`, `value`, etc.) will be mapped as expected:

```jsx
Expand All @@ -312,7 +312,7 @@ const MyTextInput = (props) => <input className="my-input" {...props} />;
/>
```

## `ignore={[...]}` {#prop-ignore}
## `ignore={[...]}`
_(String | Array)_: The event(s) that you want the `<Control>` to ignore. This can be good for performance and/or for de-cluttering the console log.

For instance, if you don't care whether a `<Control>` is focused or blurred:
Expand All @@ -325,7 +325,7 @@ For instance, if you don't care whether a `<Control>` is focused or blurred:
/>
```

## `disabled={...}` {#prop-disabled}
## `disabled={...}`
_(Any)_: The `disabled` prop works just like you'd expect for controls that support the HTML5 `disabled` attribute.

However, in `<Control>`, it can be a boolean, or a function, string, or object as a [Lodash iteratee](https://lodash.com/docs#iteratee).
Expand All @@ -348,7 +348,7 @@ For example:

(since: version 1.3.0)

## `getRef={() => ...}` {#prop-getRef}
## `getRef={() => ...}`
_(Function)_: Calls the callback provided to the `getRef` prop with the node instance. Similar to `ref`.

```jsx
Expand All @@ -358,7 +358,7 @@ _(Function)_: Calls the callback provided to the `getRef` prop with the node ins
/>
```

## `persist={false}` {#prop-persist}
## `persist={false}`
_(Boolean)_: Signifies that the field state (validation, etc.) should not persist when the component is unmounted. Default: `false`

```jsx
Expand All @@ -372,7 +372,7 @@ _(Boolean)_: Signifies that the field state (validation, etc.) should not persis
/>
```

## `getValue={(event, props) => ...}` {#prop-getValue}
## `getValue={(event, props) => ...}`
_(Function)_: Determines the value given the `event` (from `onChange`) and optionally the control component's `props`.

By default, the `getValue` function returns the value by checking if the `event` is a DOM event.
Expand All @@ -390,13 +390,12 @@ For `<Control.checkbox />`, the default `getValue` function is:
/>
```

## `isToggle={false}` {#prop-isToggle}
## `isToggle={false}`
_(Boolean)_: Signifies that the control is a toggle (e.g., a checkbox or a radio). If `true`, then some optimizations are made.

Default: `true` for `<Control.radio>` and `<Control.checkbox>`, `false` for all other controls.

## `withFieldValue={false}` {#prop-withFieldValue}
## `withFieldValue={false}`
_(Boolean)_: When `true` the `fieldValue` prop is mapped on to the child component. This prop contains information about the field's state such as its validity and whether it has been touched. This is particularly useful when using a custom component as it allows you to dynamically alter the component based on the field's state.

Default: `false`
{% endraw %}
2 changes: 0 additions & 2 deletions docs/api/Errors.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% raw %}
# Errors Component

## `<Errors />`
Expand Down Expand Up @@ -120,4 +119,3 @@ _(String | Function | Element)_: The `component`, which is the component for eac
- `fieldValue` - the current field state of the `model`
- `children` - the error message (text).
- `component={CustomError}` will wrap the error in a `<CustomError>` component, which will receive the same props as above.
{% endraw %}
Loading

0 comments on commit 0d0f51b

Please sign in to comment.