Custom Validation Code

You may add custom javascript that gets executed on the go to validate the current respondent input.

You may also cross check the values of other respondent answers in the survey using the surveyAnswers array containing all the answers to the questions that were answered by the respondent so far.

Your custom method must either return null if your check have passed or return an object with with a message property that will be shown to the user as an error message.

Here are basic sample of a method that checks that the respondent has entered something in the answer field.

/* 
 respondentAnswerValue: value that was entered by the respondent 
 answer : answer object that is being validated
 question: question object to which the answer belongs
 surveyAnswers: all respondent answers posted so far  */

function isFilled(
respondentAnswerValue, //  :string 
answer,  //  : Answer
question, // : Question 
surveyAnswers // : SurveyFormGroupAnswer[]
) {
  if (!respondentAnswerValue || respondentAnswerValue.length == 0) {
      return { message : 'please enter something'};
   } 
   return null;
}
export interface SurveyFormGroupAnswer {
  answer: Answer; // Answer to which this respondent answer belongs to
  question: Question; // Question of the answer
  answerControl: FormControl; // Form control that keeps the respondent answer value
  sectionIndex: number; // section index if the question is repetable.
  sectionId: string; // unique section id if the question is repeatable.
}

The answer control is an Angular form control object as such we can get its value using following notation answerControl.value.

Last updated

(c) 2024 Data Illusion Zumbrunn. All rights reserved. Reproduction strictly forbidden.