Toggle menu
875
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Prioritize sub questions in a text grid question

From Catglobe Wiki
Revision as of 02:04, 3 March 2009 by Catglobe (talk | contribs) (New page: ==Challenge== In order to let the respondent prioritize a list of products<br/> As a questionnaire creator<br/> I want to allow him to enter only values in a list of priorities for each pr...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Challenge

In order to let the respondent prioritize a list of products
As a questionnaire creator
I want to allow him to enter only values in a list of priorities for each product (one priority is only used once)
Example

Code

function isNumeric_LessThan6(sText)
{
	var ValidChars = "12345";
	if (sText.length != 1)
		return false;
	
	if (ValidChars.indexOf(sText) == -1) 
		return false; 
	
	return true;
}

var normalQuestionCheck = questioncheck;

function extendedQuestionCheck()
{
	var valid = normalQuestionCheck();
	if (!valid)
		return false;
		
	var usedNumbers = "";
	ErrorMessages.getInstance().clearErrorMessages();
	var msg = "";
	
	$("input:text").each(
		function(i)
		{
			if ($(this).attr("name").indexOf("QUESTION.") == 0)
			{
				//check the value
				var v = $(this).val();
				if (!isNumeric_LessThan6(v))
				{
					msg = "Only 1-5 are allowed as input";
					valid = false;
					return;
				}
				
				if (usedNumbers.indexOf(v) != -1)
				{
					valid = false;
					msg = "One value can only be specified for one row";
					return;
				}				
				
				usedNumbers = usedNumbers + v;
			}
		}
	);
	if (!valid)
		ErrorMessages.getInstance().showErrorMessage(msg); 
		
	return valid;
}

questioncheck = extendedQuestionCheck;