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

customValidation example #21

Open
anthonywebb opened this issue Oct 4, 2018 · 0 comments
Open

customValidation example #21

anthonywebb opened this issue Oct 4, 2018 · 0 comments

Comments

@anthonywebb
Copy link

I am not sure exactly how to use a "customValidation", I defined the function (along with a console.log statement to ensure it was arriving into the function), and then passed in into the form, but I dont seem to be calling the function as expected?

function validate(field) {
   console.log('validating',field);
   let error = false;
   let errorMsg = '';
   if (field.name === 'username' && !(field.value && field.value.trim())) {
     error = true;
     errorMsg = 'Username is required';
   }
   if (field.name === 'password' && !(field.value && field.value.trim())) {
     error = true;
     errorMsg = 'Password is required';
   }
   return { error, errorMsg };
}
<GenerateForm
            ref={(c) => {
              this.formGenerator = c;
            }}
            fields={fields}
            customValidation={validate}
          />
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