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

Accepting pull requests? #3

Open
readeral opened this issue Nov 14, 2017 · 2 comments
Open

Accepting pull requests? #3

readeral opened this issue Nov 14, 2017 · 2 comments

Comments

@readeral
Copy link

Hi, would you accept pull requests to update your example?

I've been using your concept for my own site, but the immutability helpers and jquery are unnecessary dependencies:

The jquery ($.isEmptyObject(this.state.validationErrors) in CreateAccount.js can be replaced with (Object.keys(this.state.validationErrors).length > 0)

And if using react with es6 making state updates immutable can be done by utilising arrow functions:

this.setState(prevState => ({
...prevState,
newState
});

Happy to make those changes and submit a pull request if you're happy to accept them.

Thanks,

Al

@readeral
Copy link
Author

And FWIW, to answer the concern of nested state (and so the use of immutability helpers) my implementation includes nested state, which I am updating as follows:

handleSubmitClicked(target) {
this.setState(prevState => ({
orderData: {
...prevState.orderData,
[target]: {
...prevState.orderData[target],
showErrors: true
}
}
}));
}

so this can be done with arrow function and spread operator reasonably easily.

@mickeypuri
Copy link

mickeypuri commented Mar 27, 2018

Very nice and elegant example! Thanks.

@readeral some good observations there 👍

As an enhancement, I would also propose showing errors for a field after the field is changed rather than waiting for submit to be pressed. ie give user early feedback. Better still after it is "touched" by hooking into the blur event of the field.

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

No branches or pull requests

2 participants