question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Only validate fields that are currently shown

See original GitHub issue

I am making a field required by adding an attribute like validation: [['string'], ['required']] to my schema. I am making the field conditionally shown using an attribute like showWhen: ['or', ['is', 'color', 'blue'], ['is', 'color', 'red]]. It seems that even when the field is not shown, validation is being run, preventing me from submitting the form.

Would it make sense to only validate fields that are actually being shown? Or, alternatively, is there any way to include the showWhen logic in the validation statement?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
andrewringlercommented, Jan 23, 2020

For anyone reading this thread if you are serializing your schema e.g. JSON.stringify and transporting it over the wire you will need to use some manual scheme to serialize your functions and then deserialize them when you read out your schema since Javascript functions are not valid JSON.

1reaction
easeqcommented, Jul 24, 2019

It does make sense to validate just the visible fields, but at this time that is possible only by using the when condition provided by yup.

Following might work for your case:

[['string'], ['when', 'color', {
       is: (value) => value === 'blue' || value == 'red',
       then: [['string'], ['required']]
}]]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Validate only fields that are visible - javascript
1 Answer 1 ... Take hidden field that contain action of radio button on change(if click on item one >> 'x', item >>'y')...
Read more >
LiveValidation only validate fields that are visible?
I'm using LiveValidation to validate fields in a form before they are submitted. I have one option where the user can select “Married” ......
Read more >
Validate only one field at a time · Issue #512
Formik validate function - pass the event's field name. It will allow the developer to validate only one field at a time.
Read more >
Validation
Formik is designed to manage forms with complex validation with ease. Formik supports synchronous and asynchronous form-level and field-level validation.
Read more >
Data Validation – How to Check User Input on HTML ...
We need form validation anytime we are accepting user input. We must ensure that the data entered is in the correct format, lies...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found