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

Conversation

anson0370
Copy link
Contributor

Sometimes I want to do something when one field changing but use another field's value. So I make this PR.

We can use onChange prop at most of the time. But when we use package like Antd, there is no way to use a custom onChange prop(the onChange is generated by getFieldDecorator()).

Or we can add an option for getFieldDecorator() to do this? Or there is another solution I do not know? Please discuss.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 87.554% when pulling a9aa789 on anson0370:pass-all-fieldsvalue-in-onchange into 616ddd3 on react-component:master.

@benjycui
Copy link
Member

benjycui commented Nov 8, 2016

You can get other fields from props

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 87.554% when pulling c8f7a3f on anson0370:pass-all-fieldsvalue-in-onchange into 616ddd3 on react-component:master.

@anson0370
Copy link
Contributor Author

@benjycui Sometimes the component will be wrapped. I can't get other fields use props.form or props.getForm() or something like these.

In my case. I must use code like props.refs.wrappedComponent.getForm().getFieldsValue() what is really ugly.

Maybe I do things wrong?

@@ -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

@anson0370
Copy link
Contributor Author

@benjycui 我决定还是打中文吧……
我就是指的这个 props ,你的意思是用 <input/>onChange 传递给上层组件或者 redux store 再传回 props 里来获取别的 field 对吧?
但 AntD 的 onChange 是不建议自己实现的,所以我就直接用 form 的 onFieldsChange 来做这件事?

可是很多时候我就只是简单想获取一下,没有强烈的需求要传给 redux store 或上层组件。还是说从规范上来说我就不应该这样做?
其实我这个需求并不一定要在这里处理,可以在 AntD 中类似这样

getFieldDecorator('field', {
  onChange(value) {
    // do something
  }
});

@benjycui
Copy link
Member

benjycui commented Nov 9, 2016

并没有不建议自行实现 onChange...

@benjycui
Copy link
Member

benjycui commented Nov 9, 2016

@benjycui benjycui closed this Nov 9, 2016
@anson0370
Copy link
Contributor Author

@benjycui sorry 我没看仔细

@anson0370 anson0370 deleted the pass-all-fieldsvalue-in-onchange branch November 9, 2016 03:53
@benjycui
Copy link
Member

benjycui commented Nov 9, 2016

我刚更新的 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants