Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/actionCreators.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Returns an action that when dispatched will reset the form values associated wit
### Note on `meta` parameter - There are some special properties available:
- `reduxMountPoint` - automatically added to every action fired, specifying which form it is associated with
- `suppressChange` - adding this to the meta object for any action creator will skip any `onChange` callbacks in the inputsConfig
- `forceAsyncValidation` - adding this to the meta object for `validateInputs` and `updateAndValidate` will force async validation even if the value is unchanged
- `validate` - included when running `validateInputs`
- `initialize` - included when running `intializeInputs`, sets all changed inputs to `pristine`
- `reset` - included when running `resetInputs`
2 changes: 1 addition & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export function updateAndValidate(inputConfig, update, meta = {}) {
if (typeof validationResult === 'boolean' || typeof validationResult === 'string' || hasAsync || !validationResult) { // Or Promise
const change = (validationResult === true || hasAsync) ? ({ // True or hasAsync, set value
value: value,
validating: currentlyValidating || (hasAsync && !unchanged) // Will be validating if async validator exists
validating: currentlyValidating || (hasAsync && !unchanged) || (hasAsync && meta.forceAsyncValidation) // Will be validating if async validator exists
}) : ({ // False returned, input invalid
value: prev,
error: typeof value === 'undefined' ? '' : value,
Expand Down
28 changes: 28 additions & 0 deletions tests/redux-inputs-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,34 @@ describe('updateAndValidate thunk', () => {
}
}));
});
it('correctly fires async validation when input is unchanged if forceAsyncValidation meta is present', () => {
const expectedActions = [{
error: false,
meta: { reduxMountPoint: 'inputs', forceAsyncValidation: true },
payload: { email: { validating: true, value: '[email protected]' }},
type: 'RI_SET_INPUT'
}, {
error: false,
meta: { reduxMountPoint: 'inputs', forceAsyncValidation: true },
payload: { email: { value: '[email protected]' }},
type: 'RI_SET_INPUT'
}];
const store = mockStore({ inputs: { email: { value: '[email protected]' } } });
const thunk = updateAndValidate({
email: {
validator: () => Promise.resolve()
}
}, {
email: '[email protected]'
},
{
forceAsyncValidation: true
});

return store.dispatch(thunk).then(() => {
expect(store.getActions()).to.deep.equal(expectedActions);
});
});
it('correctly dispatches async validation VALID changes', () => {
const expectedActions = [{
error: false,
Expand Down