Difference between revisions of "Validate the questions by using the questioncheck() function"

From Catglobe Wiki
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
*The Javascript function questioncheck() is where all the question validation stuff will be implemented. Therefore, to implement your own question validation stuff which not supported by the Catglobe system, you need to '''overwrite''' this function.
 
*The Javascript function questioncheck() is where all the question validation stuff will be implemented. Therefore, to implement your own question validation stuff which not supported by the Catglobe system, you need to '''overwrite''' this function.
*The questioncheck() function will be called/invoked by the '''quest.next()''' function when the next button is clicked.
+
*The questioncheck() function will be called/invoked by the '''quest.next()''' function when the '''Next''' button is clicked.
 
*It is '''required''' that the questioncheck() function must return the '''boolean''' values (true/false). If true, the answer value of question is valid, else the answers value of question is invalid.
 
*It is '''required''' that the questioncheck() function must return the '''boolean''' values (true/false). If true, the answer value of question is valid, else the answers value of question is invalid.
*To display error messages when the answer of question is invalid. You could use the Javascript '''alert()''' function or add your error message texts to the container which has the id: '''#errorMessages'''
+
*To display '''error messages''' when the answer of question is invalid. You could use the Javascript '''alert()''' function or add your error message texts to the container which has the id: '''#errorMessages'''
 
*In most cases, you should '''copy''' the questioncheck() before overwriting it by your own questioncheck function. To copy the questioncheck and overwrite it, please see below snippnet:
 
*In most cases, you should '''copy''' the questioncheck() before overwriting it by your own questioncheck function. To copy the questioncheck and overwrite it, please see below snippnet:
  
Line 14: Line 14:
 
  return false;
 
  return false;
 
   
 
   
  // If the old questioncheck detect that the answer of question is valided with his own rules, then we will continue the our customized validation rules.
+
  // If the old questioncheck detects that the answer of question is valid with its own rules, then we will continue with our validation rules.
 
  // Implement your own validation rules below
 
  // Implement your own validation rules below
  // your own validation rule coldes here.....numeric validation codes...
+
  // Your own validation rule coldes here.....numeric validation codes...
 
   
 
   
  // remember that it is required the this function must return the boolean values (true/false)  
+
  // Remember that it is required the this function must return the boolean values (true/false)  
 
};
 
};
 
</source>
 
</source>

Latest revision as of 07:55, 11 November 2013

Validate the questions of questionnaire by using the questioncheck() function

  • The Javascript function questioncheck() is where all the question validation stuff will be implemented. Therefore, to implement your own question validation stuff which not supported by the Catglobe system, you need to overwrite this function.
  • The questioncheck() function will be called/invoked by the quest.next() function when the Next button is clicked.
  • It is required that the questioncheck() function must return the boolean values (true/false). If true, the answer value of question is valid, else the answers value of question is invalid.
  • To display error messages when the answer of question is invalid. You could use the Javascript alert() function or add your error message texts to the container which has the id: #errorMessages
  • In most cases, you should copy the questioncheck() before overwriting it by your own questioncheck function. To copy the questioncheck and overwrite it, please see below snippnet:


var old_questioncheck = questioncheck(); // This line copy the questioncheck()
questioncheck = function() { // This line overwrite the questioncheck() by your own questioncheck

 if(!old_questioncheck()) // In most cases, we will reuse the old questioncheck to implement the validation rules that supported by Catglobe system
 return false;
 
 // If the old questioncheck detects that the answer of question is valid with its own rules, then we will continue with our validation rules.
 // Implement your own validation rules below
 // Your own validation rule coldes here.....numeric validation codes...
 
 // Remember that it is required the this function must return the boolean values (true/false) 
};