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

Commit ecf6936

Browse files
committed
Adding back erroneously deleted parts
1 parent 68ecc65 commit ecf6936

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/components/control-component.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,22 @@ class Control extends Component {
271271
model,
272272
} = this.props;
273273

274+
// If there are no async validators,
275+
// do not run async validation
274276
if (!asyncValidators) return false;
275277

278+
// If any sync validity is invalid,
279+
// do not run async validation
280+
const asyncValidatorKeys = Object.keys(asyncValidators);
281+
const syncValid = Object.keys(fieldValue.validity).every((key) => {
282+
// If validity is based on async validator, skip
283+
if (!!~asyncValidatorKeys.indexOf(key)) return true;
284+
285+
return fieldValue.validity[key];
286+
});
287+
288+
if (!syncValid) return false;
289+
276290
return (dispatch) => {
277291
mapValues(asyncValidators,
278292
(validator, key) => dispatch(actions.asyncSetValidity(model,

test/control-component-spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,17 @@ describe('Extended Control components', () => {
775775
test: modelReducer('test', { foo: '' }),
776776
});
777777

778+
TestUtils.renderIntoDocument(
779+
<Provider store={store}>
780+
<Control.text
781+
model="test.foo"
782+
validators={{
783+
required: (val) => val && val.length,
784+
}}
785+
/>
786+
</Provider>
787+
);
788+
778789
it('should initially be invalid', () => {
779790
assert.deepEqual(
780791
store.getState().testForm.foo.validity,

0 commit comments

Comments
 (0)