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);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745614783a4636167.html
评论列表(0条)