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

Commit 3401bf4

Browse files
committed
Adding documentation for programmatically submitting a Form in React-Native. Fixes #625
1 parent 20382af commit 3401bf4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

docs/api/actions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ If the promise fails, the action will:
395395
- set `.submitFailed` property of form for `model` to `true`
396396
- set `.errors` property of form for `model` to the response
397397

398-
If a promise is not provided, e.g.: `actions.submit('user')`, then dispatching the action will trigger a `<Form>` with the specified `model` to submit itself.
398+
If a promise is not provided, e.g.: `actions.submit('user')`, then dispatching the action will trigger a `<Form>` with the specified `model` to call its `onSubmit` handler.
399399

400400
### Arguments
401401
- `model` _(String | Function)_: the model to be submitted

docs/guides/react-native.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,27 @@ The use of `updateOn="blur"` will work as expected for the controls, and is set
5050

5151
By default, the `<Form>` component is rendered as a `<View>`. It handles validity as expected, as well as partial models for child `<Control>` components, but it does not have an `onSubmit` mechanism.
5252

53-
```js
53+
```jsx
5454
import { Form, Control } from 'react-redux-form/native';
5555

5656
// render...
57-
<Form model="user">
57+
<Form model="user" onSubmit={/* ... */}>
58+
<Control.TextInput model=".firstName" />
59+
<Control.TextInput model=".lastName" />
60+
</Form>
61+
```
62+
63+
To submit a React Native form programmatically:
64+
65+
1. Ensure that the `<Form model="foo">` component has an `onSubmit={(values) => ...}` callback.
66+
2. Dispatch a submit action for the form's model (and no other arguments): `dispatch(actions.submit('foo'))`
67+
68+
```jsx
69+
<Form model="user" onSubmit={(vals) => console.log(vals)}>
5870
<Control.TextInput model=".firstName" />
5971
<Control.TextInput model=".lastName" />
72+
73+
<Button onPress={() => dispatch(actions.submit('user'))} />
6074
</Form>
6175
```
6276

0 commit comments

Comments
 (0)