diff --git a/classes/eval/LimeExpressionManager.php b/classes/eval/LimeExpressionManager.php
index abe12f80694..5e5c8284b61 100644
--- a/classes/eval/LimeExpressionManager.php
+++ b/classes/eval/LimeExpressionManager.php
@@ -872,7 +872,8 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
case 'S': //SHORT FREE TEXT
case 'T': //LONG FREE TEXT
case 'U': //HUGE FREE TEXT
- $sq_name = '(!regexMatch("' . $preg . '", ' . $sq['varName'] . '.NAOK))';
+ // TODO - should empty always be an option? or require that empty be an explicit option in the regex?
+ $sq_name = '(if((strlen('.$sq['varName'].'.NAOK)==0),0,!regexMatch("' . $preg . '", ' . $sq['varName'] . '.NAOK)))';
break;
default:
break;
@@ -889,7 +890,7 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'preg',
- 'eqn' => '(count(' . implode(', ', $sq_names) . ') > 0)',
+ 'eqn' => '(sum(' . implode(', ', $sq_names) . ') == 0)',
'qid' => $questionNum,
'tip' => $this->gT('All entries must conform to this regular expression:') . " " . str_replace(array('{','}'),array('{ ',' }'), $preg),
);
@@ -2490,7 +2491,7 @@ function _ValidateGroup($groupSeq, $debug=false)
. ($grel ? 'relevant ' : " irrelevant ")
. (($ghidden && $grel) ? " always-hidden " : ' ')
. ($gmandViolation ? " (missing a relevant mandatory) " : ' ')
- . ($gvalid ? '' : " (missing a relevant mandatory) ")
+ . ($gvalid ? '' : " (fails at least one validation rule) ")
. "
\n"
. implode('', $messages);
}
@@ -2642,6 +2643,8 @@ function _ValidateGroup($groupSeq, $debug=false)
'gid' => $LEM->gseq2info[$groupSeq]['gid'],
'anyUnanswered' => ((strlen($unansweredSQList) > 0) ? true : false),
'anyErrors' => (($gmandViolation || !$gvalid) ? true : false),
+ 'valid' => $gvalid,
+ 'mandViolation' => $gmandViolation,
'show' => (($grel && !$ghidden) ? true : false),
);
@@ -3035,6 +3038,8 @@ function _ValidateQuestion($questionSeq, $debug=false)
$qvalid=true; // assume valid unless discover otherwise
$hasValidationEqn=false;
$prettyPrintValidEqn=''; // assume no validation eqn by default
+ $validationJS=''; // assume can't generate JavaScript to validate equation
+ $validTip=''; // default is none
// TODO - when there are multiple questions which each use the same validation, need to know which sub-questions are invalid
if (isset($LEM->qid2validationEqn[$qid]))
{
@@ -3047,15 +3052,21 @@ function _ValidateQuestion($questionSeq, $debug=false)
{
$qvalid=false; // default to invalid so that can show the error
}
+ else
+ {
+ $validationJS = $LEM->em->GetJavaScriptEquivalentOfExpression();
+ }
if ($debug)
{
$prettyPrintValidEqn = $LEM->em->GetPrettyPrintString();
+ }
- // Also preview the Validation Tip
- $stringToParse = implode('
',$LEM->qid2validationEqn[$qid]['tips']);
- // pretty-print them
- $LEM->ProcessString($stringToParse, $qid,NULL,false,1,1,false,false);
- $prettyPrintValidTip = $LEM->GetLastPrettyPrintExpression(); }
+ $stringToParse = implode('
',$LEM->qid2validationEqn[$qid]['tips']);
+ // pretty-print them
+ $validTip = $LEM->ProcessString($stringToParse, $qid,NULL,false,1,1,false,false);
+ if ($debug) {
+ $prettyPrintValidTip = $LEM->GetLastPrettyPrintExpression();
+ }
}
else
{
@@ -3079,7 +3090,7 @@ function _ValidateQuestion($questionSeq, $debug=false)
. ($qrel ? 'relevant' : " irrelevant ")
. ($qhidden ? " always-hidden " : ' ')
. (($qInfo['mandatory'] == 'Y')? ' mandatory' : ' ')
- . (($hasValidationEqn) ? (!$qvalid ? " (missing a relevant mandatory) " : ' valid') : '')
+ . (($hasValidationEqn) ? (!$qvalid ? " (fails validation rules) " : ' valid') : '')
. ($qmandViolation ? " (missing a relevant mandatory) " : ' ')
. $prettyPrintRelEqn
. "
\n";
@@ -3091,13 +3102,21 @@ function _ValidateQuestion($questionSeq, $debug=false)
if ($prettyPrintValidTip != '')
{
- $debug_qmessage .= '----Validation Tip: ' . $prettyPrintValidTip . "
\n";
+ $debug_qmessage .= '----Pretty Validation Tip: ' . $prettyPrintValidTip . "
\n";
+ }
+ if ($validTip != '')
+ {
+ $debug_qmessage .= '----Validation Tip: ' . $validTip . "
\n";
}
if ($prettyPrintValidEqn != '')
{
$debug_qmessage .= '----Validation Eqn: ' . $prettyPrintValidEqn . "
\n";
}
+ if ($validationJS != '')
+ {
+ $debug_qmessage .= '----Validation JavaScript: ' . $validationJS . "
\n";
+ }
// what are the database question codes for this question?
$subQList = '{' . implode('}, {', explode('|',$LEM->qid2code[$qid])) . '}';
@@ -3151,7 +3170,8 @@ function _ValidateQuestion($questionSeq, $debug=false)
'unansweredSQs' => implode('|',$unansweredSQs),
'valid' => $qvalid,
'validEqn' => $prettyPrintValidEqn,
- 'validTip' => $prettyPrintValidTip,
+ 'validTip' => $validTip,
+ 'validJS' => $validationJS,
'invalidSQs' => (isset($invalidSQs) ? $invalidSQs : ''),
'relevantSQs' => implode('|',$relevantSQs),
'irrelevantSQs' => implode('|',$irrelevantSQs),
diff --git a/group1.php b/group1.php
index 75f26f326d7..667e1724862 100644
--- a/group1.php
+++ b/group1.php
@@ -86,6 +86,7 @@
if ($LEMdebugLevel>=2) {
$LEMmsg = $moveResult['message'];
}
+ $ginfo = LimeExpressionManager::GetGroupIndexInfo($moveResult['gseq']);
}
// We do not keep the participant session anymore when the same browser is used to answer a second time a survey (let's think of a library PC for instance).
@@ -501,13 +502,13 @@
// TMSW Mandatory -> EM
// TMSW - get question-level error messages - don't call **_popup() directly
// if (isset($notanswered) && $notanswered && $_SESSION['maxstep'] != $_SESSION['step'])
- if (isset($notanswered) && $notanswered && $_SESSION['prevstep'] == $_SESSION['step'])
+ if ($ginfo['mandViolation'] && $_SESSION['prevstep'] == $_SESSION['step'])
{
list($mandatorypopup, $popup)=mandatory_popup($ia, $notanswered);
}
//Display the "validation" popup if necessary
- if (isset($notvalidated) && $notvalidated && $_SESSION['prevstep'] == $_SESSION['step'])
+ if (!$ginfo['valid'] && $_SESSION['prevstep'] == $_SESSION['step'])
{
list($validationpopup, $vpopup)=validation_popup($ia, $notvalidated);
}
@@ -1315,13 +1316,13 @@ function checkconditions(value, name, type)
//Display the "mandatory" message on page if necessary
// TMSW Mandatory -> EM
-if (isset($showpopups) && $showpopups == 1 && isset($notanswered) && is_array($notanswered) && count($notanswered) > 0 && $_SESSION['prevstep'] == $_SESSION['step'])
+if (isset($showpopups) && $showpopups == 1 && $ginfo['mandViolation'] && $_SESSION['prevstep'] == $_SESSION['step'])
{
echo "
" . $clang->gT("One or more mandatory questions have not been answered. You cannot proceed until these have been completed.") . "
"; } //Display the "validation" message on page if necessary -if (isset($showpopups) && $showpopups == 1 && isset($notvalidated) && is_array($notvalidated) && count($notvalidated) > 0 && $_SESSION['prevstep'] == $_SESSION['step']) +if (isset($showpopups) && $showpopups == 1 && !$ginfo['valid'] && $_SESSION['prevstep'] == $_SESSION['step']) { echo "" . $clang->gT("One or more questions have not been answered in a valid manner. You cannot proceed until these answers are valid.") . "
"; } diff --git a/qanda1.php b/qanda1.php index 1e886ab4c25..89c9bf7d638 100644 --- a/qanda1.php +++ b/qanda1.php @@ -812,11 +812,21 @@ function retrieveAnswers($ia, $notanswered=null, $notvalidated=null, $filenotval $qtitle .= $mandatory_msg; $question_text['man_message'] = $mandatory_msg; - $validation_msg = validation_message($ia); + if (($_SESSION['step'] != $_SESSION['maxstep']) || ($_SESSION['step'] == $_SESSION['prevstep'])) { + $validation_msg = validation_message($ia); + } + else { + $validation_msg = ''; + } $qtitle .= $validation_msg; $question_text['valid_message'] = $validation_msg; - $file_validation_msg = file_validation_message($ia); + if (($_SESSION['step'] != $_SESSION['maxstep']) || ($_SESSION['step'] == $_SESSION['prevstep'])) { + $file_validation_msg = file_validation_message($ia); + } + else { + $file_validation_msg = ''; + } $qtitle .= $ia[4] == "|" ? $file_validation_msg : ""; $question_text['file_valid_message'] = $ia[4] == "|" ? $file_validation_msg : ""; @@ -964,10 +974,16 @@ function validation_message($ia) if (!$qinfo['valid']) { $help = $qinfo['info']['help']; if (strlen($help) > 0) { - $help .= '