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

resetting a form fires onChange for every field on form #103

Open
andrewlorenz opened this issue Jul 3, 2018 · 1 comment
Open

resetting a form fires onChange for every field on form #103

andrewlorenz opened this issue Jul 3, 2018 · 1 comment

Comments

@andrewlorenz
Copy link

A programmatic form reset should not fire a UI event (i.e. one that exists to capture manual interaction from the user), but it does. In the example below, onChange fires once per input field on the form that has been reset:

resetForm = () => { this.refs.form.reset() }
onChange = () => { console.log("onChange") }
render() {
  return (
    <Formsy onChange={this.onChange} ref="form" >
      < ... 5 input fields ... >
    </Formsy>
}

It is fine for a UI event to run code, but it makes no sense for code that runs to fire UI events!
My use case is that I need to track whether the form has been modified or not, and Formsy doesn't provide a way to check the pristine state of the form, only each field on it. So I need to implement a separate state tracker (boolean) which is set to true when a field is changed, and set to false on reset or save.

@MilosRasic
Copy link
Contributor

Not sure about the first statement about firing the change event. We usually use it to update some state and we probably want to update it when the form is programatically reset too.

The problem with checking if the form is pristine is often encountered and we've had it on the project I'm working on too. We should definitely implement pristine flag on the form in 2.0

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

No branches or pull requests

3 participants