Skip to content
This repository was archived by the owner on Nov 26, 2021. It is now read-only.

Commit d9d143b

Browse files
committed
update .
1 parent 171bda7 commit d9d143b

4 files changed

Lines changed: 894 additions & 817 deletions

File tree

README-zh_CN.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ const schemas = {
4444
messages: '不能为空 | 请输入有效的电子邮件地址 | 不能超过{{param}}个字符',
4545
},
4646
hobby: {
47-
rules: 'required | selectLimit(2)',
48-
messages: '不能为空 | 至少选择{{param}}项',
47+
rules: 'requiredField(email) | selectLimit(2)',
48+
messages: '邮件和爱好至少填写一项 | 至少选择{{param}}项',
4949
},
5050
};
5151

@@ -56,6 +56,10 @@ const methods = {
5656
}
5757
return false;
5858
},
59+
requiredField(field, param) {
60+
const otherField = this.fields[param];
61+
return this.required(field) || (otherField.result && this.required(otherField));
62+
},
5963
};
6064
```
6165

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const schemas = {
3838
messages: 'Can not be empty! | Please enter a valid email address. | Can not exceed {{param}} characters.',
3939
},
4040
hobby: {
41-
rules: 'required | selectLimit(2)',
42-
messages: 'Can not be empty! | Select at least {{param}}.',
41+
rules: 'requiredField(phone) | selectLimit(2)',
42+
messages: 'email and hobby at least one entry! | Select at least {{param}}.',
4343
},
4444
};
4545

@@ -50,6 +50,10 @@ const methods = {
5050
}
5151
return false;
5252
},
53+
requiredField(field, param) {
54+
const otherField = this.fields[param];
55+
return this.required(field) || (otherField.result && this.required(otherField));
56+
},
5357
};
5458
```
5559

src/Field.jsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
import React, { PropTypes } from 'react';
22

3-
const propTypes = {
4-
name: PropTypes.string.isRequired,
5-
};
6-
7-
const contextTypes = {
8-
fields: PropTypes.object.isRequired,
9-
initField: PropTypes.func.isRequired,
10-
onFormChange: PropTypes.func.isRequired,
11-
};
12-
133
/**
144
* Field component
155
* @param FormComponent
@@ -46,7 +36,14 @@ const Field = (FormComponent, fieldType, {
4636
);
4737
};
4838

49-
Field.propTypes = propTypes;
50-
Field.contextTypes = contextTypes;
39+
Field.propTypes = {
40+
name: PropTypes.string.isRequired,
41+
};
42+
43+
Field.contextTypes = {
44+
fields: PropTypes.object.isRequired,
45+
initField: PropTypes.func.isRequired,
46+
onFormChange: PropTypes.func.isRequired,
47+
};
5148

5249
export default Field;

0 commit comments

Comments
 (0)