Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass all fields value into onFieldsChange method #42

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -23,4 +23,5 @@ node_modules
build
dist
lib
coverage
coverage
.vscode
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -119,7 +119,7 @@ preset messages of [async-validator](https://github.com/yiminghe/async-validator

Get new props transfered to WrappedComponent. Defaults to props=>props.

### formOption.onFieldsChange(props, fields)
### formOption.onFieldsChange(props, fields, allFieldsValue)

Called when field changed, you can dispatch fields to redux store.

Expand Down
2 changes: 1 addition & 1 deletion src/createBaseForm.js
Expand Up @@ -384,7 +384,7 @@ function createBaseForm(option = {}, mixins = []) {
changedFieldsName.forEach((f) => {
changedFields[f] = this.getField(f);
});
onFieldsChange(this.props, changedFields);
onFieldsChange(this.props, changedFields, this.getFieldsValue());
}
this.forceUpdate();
},
Expand Down
4 changes: 3 additions & 1 deletion tests/map.spec.js
Expand Up @@ -37,11 +37,13 @@ describe('map usage', () => {
it('onFieldsChange works', () => {
const Test = createForm({
withRef: true,
onFieldsChange(props, fields) {
onFieldsChange(props, fields, allFields) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get fields from this props,for you had pass fields to upper component by onChange

expect(Object.keys(fields).length).to.be(1);
const field = fields.normal;
expect(field.name).to.be('normal');
expect(field.value).to.be('3');
expect(allFields.normal).to.be('3');
expect(allFields.normal2).to.be(undefined);
},
mapPropsToFields(props) {
return {
Expand Down