I have been given a task to change the validation of the form. Requirement is to validate the form when one of the N questions have been answered. I'm sharing the code of how validation is working currently, i.e. it validates form when all of the questions are answered. You can see the questionValidation key here that has the yup validation inside.
{
companyName: 'ABC',
policyName: 'ABCDEFG',
questionValidation: {
'Question 1?': Yup.string()
.matches('No', 'Plan ineligible')
.required('Required'),
'Question 2?': Yup.string()
.matches('No', 'Plan ineligible')
.required('Required'),
'Question 3?': Yup.string()
.matches('Yes', 'Plan ineligible')
.required('Required'),
},
questionInitialValues: {
'Question 1?':
'',
'Question 2?':
'',
'Question 3?':
'',
},
questionGroups: [
{
validationType: 'every',
questions: [
{
label: 'Yes/No',
question:
'Question 1?',
questionType: 'select',
answers: ['Yes', 'No'],
knockoutAnswers: ['Yes'],
questionID: 66,
},
{
label: 'Yes/No',
question:
'Question 2?',
questionType: 'select',
answers: ['Yes', 'No'],
knockoutAnswers: ['Yes'],
questionID: 69,
},
{
label: 'Yes/No',
question:
'Question 3?',
questionType: 'select',
answers: ['Yes', 'No'],
knockoutAnswers: ['No'],
questionID: 72,
},
],
},
],
}
Need to change code in questionValidation so that validation can be done when one of the N fields is answered. How to validates the form is written below
<FormDialog
title="Test"
...
validationSchema={knockoutQuestions?.questionValidation}
/>