Is there a way to have questions that are only mandatory when the survey is marked as complete? I would like users to be able to move between the pages of the survey without having to answer all of the mandatory questions on the page.
Make questions mandatory only when survey is marked as complete
Answers approved by surveyjs Support
Hello,
I have added a new property several days ago: survey.ignoreValidation = true;
, here is the related GitHub issue. It will be available in the next minor version (1.1.6) that we will release likely tomorrow.
You will be able to use it: set it to true in the beginning and then set to false when you need it.
Please note, this property is not serializable and you may set it in run-time only.
Thank you,
Andrew
SurveyJS Team
Thanks Andrew,
Is there a way to catch the complete event when completing the form, turn on validation and check that all validations on all pages have been met, and if so complete the survey?
To add to my previous comment, I tried adding an onCompleting event which set ignoreValidation to false but this didn't enable validation before completing the survey
Hello Conor,
Here is the function code you are looking for:
JavaScriptfunction isSurveyHasErrors(survey) {
for(var i = 0; i < survey.visiblePages.length; i ++) {
// the first parameter (false) tells do not show errors and the second parameter do not focus the first question with error
if(survey.visiblePages[i].hasError(false, false)) return true;
}
return false;
}
Thank you,
Andrew
SurveyJS Team