admin管理员组文章数量:1433531
In this example, I have a form to update user information and it is written in React with redux-form 6.5. I'm a newbie with this stack.
The render form function is like:
render() {
const { handleSubmit } = this.props;
return (
<form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
<Field name="name" ponent="input" type="text"/>
<Field name="surname" ponent="input" type="text"/>
<button action="submit">Sign in</button>
</form>
);
I have the reduxForm connection:
const extendedComponent = reduxForm({
form: 'userdetail',
validate
})(UserDetail);
And I have submit handler:
handleFormSubmit(user) {
// TODO: how can I get only the touched fields?
this.props.updateUser(user);
}
I receive correctly the object user after the validation, I send the PUT call and everything works fine.
But I don't like to send all the data in the PUT, my wish is to send only the edited data to the PUT. I understand that I could retrieve the initialValues and pare all fields.
There is another way? How can I get only the touched fields?
Which is the best practice to do this?
It seems to me a mon task and I'm not finding anything about that, so I am assuming I'm pletely missing the point.
Thank you all :)
In this example, I have a form to update user information and it is written in React with redux-form 6.5. I'm a newbie with this stack.
The render form function is like:
render() {
const { handleSubmit } = this.props;
return (
<form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}>
<Field name="name" ponent="input" type="text"/>
<Field name="surname" ponent="input" type="text"/>
<button action="submit">Sign in</button>
</form>
);
I have the reduxForm connection:
const extendedComponent = reduxForm({
form: 'userdetail',
validate
})(UserDetail);
And I have submit handler:
handleFormSubmit(user) {
// TODO: how can I get only the touched fields?
this.props.updateUser(user);
}
I receive correctly the object user after the validation, I send the PUT call and everything works fine.
But I don't like to send all the data in the PUT, my wish is to send only the edited data to the PUT. I understand that I could retrieve the initialValues and pare all fields.
There is another way? How can I get only the touched fields?
Which is the best practice to do this?
It seems to me a mon task and I'm not finding anything about that, so I am assuming I'm pletely missing the point.
Thank you all :)
Share Improve this question asked Feb 9, 2017 at 21:48 LattanzioLattanzio 1031 silver badge7 bronze badges1 Answer
Reset to default 7According to the maintainer of the redux-form
project: "That's not a feature of the library".
In that response, he remends handling the diffing yourself or using a pre-existing library, like object-diff.
For example like this:
import diff from 'object-diff'
handleFormSubmit(user, dispatch, props) {
const { initialValues } = props
const changedValues = diff(initialValues, user)
this.props.updateUser(changedValues);
}
本文标签: javascriptreduxformSubmit only edited fieldStack Overflow
版权声明:本文标题:javascript - redux-form - Submit only edited field - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745614782a2666332.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论