Skip to content

Commit

Permalink
fix: Fixed #30
Browse files Browse the repository at this point in the history
  • Loading branch information
foxhound87 committed Sep 17, 2016
1 parent 9c383e1 commit 5f1e614
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions demo/src/components/FormRegisterMaterial.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const FormRegister = ({ form }) => (
<br />
<div className="ctrl">
<button
disabled={!form.isValid}
type="submit"
onClick={form.handleOnSubmit}
>Submit</button>
Expand Down
15 changes: 6 additions & 9 deletions docs/CustomValidationFunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ export function isEmail({ field }) {
```javascript
const fields = {
username: {
label: 'Username',
value: '[email protected]',
validate: [isEmail, shouldBeEqualTo('email')],
related: ['email'],
},
...
email: {
label: 'Email',
value: '[email protected]',
validate: isEmail,
related: ['username'],
related: ['emailConfirm'],
},
emailConfirm: {
label: 'Confirm Email',
validate: [isEmail, shouldBeEqualTo('email')],
},
...
};
Expand Down
14 changes: 14 additions & 0 deletions docs/DefiningFields.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')],
},
};
1 change: 1 addition & 0 deletions src/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 4 additions & 1 deletion tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 5f1e614

Please sign in to comment.