I'm working on a project where the client would like to allow 5 questions to be blank, then the respondent should be prompted to answer the question and if they don't they should be terminated. Only half of the respondents should be given this option, the other half should be required to answer.
I've worked with the force response/ allow skip logic before, using the code from https://legacy.sawtoothsoftware.com/forum/19763/show-message-but-then-let-respondent-continue as a starting point
I've added a whole number pass in field "skipcount" that is set to 0 on the intro screen. What I'm having trouble with is advancing that field dynamically.
I've tried using the following as custom verification
var flag = $('#customErrorFlag').val();
var numSkips = [% skipcount %];
var m = [% smode %];
var response = SSI_GetValue("[% QuestionName() %]");
if(m!=2 && !response){
strErrorMessage = "A response to this question is required";
};
if(m==2 && !response && !flag){
request =true;
[% SetValue(skipcount,skipcount+1) %];
}
if(m==2 && !response && !flag && numSkips>=4){
request =true;
strErrorMessage = "Please provide a response to this question.";
}
$('#customErrorFlag').val(1);
But the Sawtooth Script activates on page load, not during the verification of the question, so the skipcount is artificially inflated, and the survey gets terminated even when no questions have been skipped.