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

Performing a reset without running the validation #417

Open
lennardschutter opened this issue Jan 23, 2017 · 10 comments
Open

Performing a reset without running the validation #417

lennardschutter opened this issue Jan 23, 2017 · 10 comments

Comments

@lennardschutter
Copy link

I am loading data fetched from the server on a larger form and I would like to pass this in to my Formsy.

To do this I use form.reset(data) to pass the data in to the form. Now the issue is that this automatically runs the validation which looks bad for the customer since half the form could be red already (from a partial save).

Is there a way we can pass new (or initial) data to Formsy without running the validation?

@aesopwolf
Copy link
Collaborator

@lennardschutter what version of formsy-react are you on? If things were working correctly before and suddenly changed it was probably due to the 0.19.1 release. See the discussion here 57f97cb

In short, you can use isFormSubmitted() to conditionally show your errors.

@lennardschutter
Copy link
Author

@aesopwolf it seems to happen on all versions for me. I think it might have to do with a custom validation rule I added for isRequired (I don't want to use the HTML5 implementation for this to keep the form and UX consistent).

Formsy.addValidationRule('isRequired', (values, value) => {
  return value && value.toString().trim().length;
});

@aesopwolf
Copy link
Collaborator

Might be worth using 0.19.1 then and conditionally showing your errors by using isFormSubmitted().

The validations will run but you will only display the errors if the form has been submitted.

Or I might be reading your issue wrong. What do you mean by "from a partial save"?

@lennardschutter
Copy link
Author

So if I understand correctly IisFormSubmitted() that on the input component? Not a big issue but it is a little bit annoying on large forms.

At the moment I am working around the issue by not setting the model via reset() but on each individual input. As you would understand it would be a lot easier if I could just call reset(model, false) eg. to populate the without running any validation.

Just to give you a little more context. The form I built is a confirmation form that confirms some final details before handing out some information. In this form some information might already be filled out in another part of the application but others fields might not have.

@aesopwolf
Copy link
Collaborator

Never mind my comment about 0.19.1, we actually just issued a rollback of that version. (long story).

Back to your issue... Would you mind copy/pasting your Formsy.Form component and also your custom form element (just one should be enough)? It will help me a lot to debug this.

@lennardschutter
Copy link
Author

lennardschutter commented Jan 24, 2017

I just created a PR #420 for this.

Might be a better way to set the initial form data.

I am actually using formsy-react-components.

@aesopwolf
Copy link
Collaborator

Hmm, that looks like it will work. Mind giving me a little bit to think about it? I might want to wait for the 1.0.0 release to expose the new method.

@lennardschutter
Copy link
Author

That is alright. As I said I have got a workaround in my app for now. I will wait until we can implement something like this before I migrate my other forms to Formsy.

@Lazarencjusz
Copy link

Hi guys, how is it going with this bug? I have 1.1.4 and stil see it.

@Lazarencjusz
Copy link

Lazarencjusz commented May 1, 2018

btw. this workaround stops work when you set required property to your Input wrapper. So, still, to forece it to work correctly, you need to remove required property and add your custom validator.

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

3 participants