From 5f1e6145eee09e2c82eda9da8c85c08c8257630b Mon Sep 17 00:00:00 2001 From: Claudio Savino Date: Sat, 17 Sep 2016 17:20:26 +0200 Subject: [PATCH] fix: Fixed #30 --- demo/src/components/FormRegisterMaterial.jsx | 1 + docs/CustomValidationFunctions.md | 15 ++++++--------- docs/DefiningFields.md | 14 ++++++++++++++ src/Field.js | 1 + tests/test.js | 5 ++++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/demo/src/components/FormRegisterMaterial.jsx b/demo/src/components/FormRegisterMaterial.jsx index b3e72801..ad38b0ba 100755 --- a/demo/src/components/FormRegisterMaterial.jsx +++ b/demo/src/components/FormRegisterMaterial.jsx @@ -72,6 +72,7 @@ const FormRegister = ({ form }) => (
diff --git a/docs/CustomValidationFunctions.md b/docs/CustomValidationFunctions.md index a91265ad..03724d84 100644 --- a/docs/CustomValidationFunctions.md +++ b/docs/CustomValidationFunctions.md @@ -24,17 +24,14 @@ export function isEmail({ field }) { ```javascript const fields = { - username: { - label: 'Username', - value: 's.jobs@apple.com', - validate: [isEmail, shouldBeEqualTo('email')], - related: ['email'], - }, + ... email: { label: 'Email', - value: 's.jobs@apple.com', - validate: isEmail, - related: ['username'], + related: ['emailConfirm'], + }, + emailConfirm: { + label: 'Confirm Email', + validate: [isEmail, shouldBeEqualTo('email')], }, ... }; diff --git a/docs/DefiningFields.md b/docs/DefiningFields.md index 86b8e78e..30dfad3e 100644 --- a/docs/DefiningFields.md +++ b/docs/DefiningFields.md @@ -70,3 +70,17 @@ const fields = { }; ``` +### Set `related` fields to be validated at the same time + +```javascript +const fields = { + email: { + label: 'Email', + validate: isEmail, + related: ['emailConfirm'], // <<--- + }, + emailConfirm: { + label: 'Confirm Email', + validate: [isEmail, shouldBeEqualTo('email')], + }, +}; diff --git a/src/Field.js b/src/Field.js index 21d089f3..d982ee73 100644 --- a/src/Field.js +++ b/src/Field.js @@ -216,6 +216,7 @@ export default class Field { return (!_.isEmpty(this.validationAsyncData) && (this.validationAsyncData.valid === false)) || (this.validationErrorStack.length !== 0) + || _.isString(this.asyncErrorMessage) || _.isString(this.errorMessage); } diff --git a/tests/test.js b/tests/test.js index e1f30697..0e6177f3 100644 --- a/tests/test.js +++ b/tests/test.js @@ -64,7 +64,7 @@ describe('Form isValid', () => { it('$H isValid should be true', () => expect($H.isValid).to.be.true); it('$I isValid should be true', () => expect($I.isValid).to.be.true); it('$L isValid should be false', () => expect($L.isValid).to.be.false); - it('$M isValid should be true', () => expect($M.isValid).to.be.true); + it('$M isValid should be false', () => expect($M.isValid).to.be.false); it('$N isValid should be false', () => expect($N.isValid).to.be.false); }); @@ -170,6 +170,9 @@ describe('others fields', () => { it('$M username.initial should be equal to "SteveJobs"', () => expect($M.fields.username.initial).to.be.equal('SteveJobs')); + it('$M username.isValid should be false', () => + expect($M.fields.username.isValid).to.be.false); + it('$N email.isValid should be false', () => expect($N.fields.email.isValid).to.be.false);