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

How/when to use initValidation? #53

Open
arteforme opened this issue Mar 20, 2020 · 0 comments
Open

How/when to use initValidation? #53

arteforme opened this issue Mar 20, 2020 · 0 comments

Comments

@arteforme
Copy link

Summary

I want to reset $validation passed to my component that's wrapped by validated. I tried calling initValidation within validated; however, that did not work. How/when do I call initValidation so that I can reset the validation?

Details

I'm trying to implement the following UX:

  1. User visits page with form
  2. User fills out fields in form
  3. User submits form
  4. After form is submitted, the fields are cleared so they can resubmit the form with new/different data.

I have the validation in place as per the documentation and it is working; however, I'm trying to find a way to reset the properties on the $validation prop so that the form doesn't appear to be invalid when their values are reset to their defaults via setState

Is the correct way to achieve this by calling initValidation()? If so, when should this method be called? I've tried calling it in validated. For example:

const validatedComponent = validated((props) => {
  const { shouldReset } = props;
  
  if(shouldReset) {
    initValidation();
  }

  return {
    fields: ['quantity'],
    validations: [
        [
          (value) => value ? true : 'Required',
          parentCompany,
          startCase(viewModelKeyMap.parentCategory)
        ]
      ]
  };
})(Component);

But this doesn't seem to work.

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

1 participant