Skip to content

How/when to use initValidation? #53

@arteforme

Description

@arteforme

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions