Skip to content

Commit

Permalink
New feature #12240: Validation settings for "array by column" questio…
Browse files Browse the repository at this point in the history
…n type

New feature : Add em_validation_q to list of choice (dropdown and radio)
Fixed issue : EM expression on other for list dropdown didn't work
  • Loading branch information
Shnoulle committed Jan 19, 2018
1 parent fd57054 commit ea543a5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 33 deletions.
57 changes: 36 additions & 21 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -2974,23 +2974,22 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$em_validation_q_tip = '';
}


// em_validation_q - an EM validation equation that must be satisfied for the whole question. Uses 'this' in the equation
if (isset($qattr['em_validation_q']) && !is_null($qattr['em_validation_q']) && trim($qattr['em_validation_q']) != '')
{
$em_validation_q = $qattr['em_validation_q'];
$sq_names = array();
if ($hasSubqs) {
$subqs = $qinfo['subqs'];
$sq_names = array();
foreach ($subqs as $sq) {
$sq_name = NULL;
switch ($type)
{
switch ($type) {
case 'A': //ARRAY (5 POINT CHOICE) radio-buttons
case 'B': //ARRAY (10 POINT CHOICE) radio-buttons
case 'C': //ARRAY (YES/UNCERTAIN/NO) radio-buttons
case 'E': //ARRAY (Increase/Same/Decrease) radio-buttons
case 'F': //ARRAY (Flexible) - Row Format
case 'H': //ARRAY (Flexible) - Col Format
case 'K': //MULTIPLE NUMERICAL QUESTION
case 'Q': //MULTIPLE SHORT TEXT
case ';': //ARRAY (Multi Flexi) Text
Expand All @@ -3004,16 +3003,16 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
case 'T': //LONG FREE TEXT
case 'U': //HUGE FREE TEXT
case 'D': //DATE
if ($this->sgqaNaming)
{
if ($this->sgqaNaming) {
$sq_name = '!(' . preg_replace('/\bthis\b/',(string)substr($sq['jsVarName'],4), $em_validation_q) . ')';
}
else
{
} else {
$sq_name = '!(' . preg_replace('/\bthis\b/',$sq['varName'], $em_validation_q) . ')';
}
break;
case 'L':
case '!':
default:
// Nothing to do : no realsubq, set it after
break;
}
if (!is_null($sq_name)) {
Expand All @@ -3034,6 +3033,21 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
);
}
}
// No subqs or false subqs (L and !)
if (empty($sq_names)) {
if ($this->sgqaNaming) {
$eqn = '(' . preg_replace('/\bthis\b/',$qinfo['sgqa'], $em_validation_q) . ')';
} else {
$eqn = '(' . preg_replace('/\bthis\b/',$qinfo['varName'], $em_validation_q) . ')';
}
$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'em_validation_q',
'class' => 'q_fn_validation',
'eqn' => $eqn,
'qid' => $questionNum,
);
}
}
else
{
Expand Down Expand Up @@ -3880,7 +3894,6 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
case 'C': //ARRAY (YES/UNCERTAIN/NO) radio-buttons
case 'E': //ARRAY (Increase/Same/Decrease) radio-buttons
case 'F': //ARRAY (Flexible) - Row Format
case 'H': //ARRAY (Flexible) - Column Format // note does not have javatbd equivalent - so array filters don't work on it
case 'K': //MULTIPLE NUMERICAL QUESTION // note does not have javatbd equivalent - so array filters don't work on it, but need rowdivid to process validations
case 'M': //Multiple choice checkbox
case 'P': //Multiple choice with comments checkbox + text
Expand All @@ -3890,16 +3903,21 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
$varName = $fielddata['title'] . '_' . $fielddata['aid'];
$question = $fielddata['subquestion'];
// $question = $fielddata['question'] . ': ' . $fielddata['subquestion'];
if ($type != 'H') {
if ($type == 'P' && preg_match("/comment$/", $sgqa)) {
// $rowdivid = substr($sgqa,0,-7);
}
else {
$sqsuffix = '_' . $fielddata['aid'];
$rowdivid = $sgqa;
}
if ($type == 'P' && preg_match("/comment$/", $sgqa)) {
// $rowdivid = substr($sgqa,0,-7);
}
else {
$sqsuffix = '_' . $fielddata['aid'];
$rowdivid = $sgqa;
}
break;
case 'H': //ARRAY (Flexible) - Column Format
$csuffix = $fielddata['aid'];
$varName = $fielddata['title'] . '_' . $fielddata['aid'];
$question = $fielddata['subquestion'];
$sqsuffix = '_' . $fielddata['aid'];
$rowdivid = $sgqa; // Really bad name here … because row are subquestion not row …
break;
case ':': //ARRAY (Multi Flexi) 1 to 10
case ';': //ARRAY (Multi Flexi) Text
$csuffix = $fielddata['aid'];
Expand Down Expand Up @@ -4043,7 +4061,6 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
if($hidden && $type!="*"){
$jsVarName_on = '';
}

if (!is_null($rowdivid) || $type == 'L' || $type == 'N' || $type == '!' || $type == 'O' || !is_null($preg)
|| $type == 'S' || $type == 'D' || $type == 'T' || $type == 'U' || $type == '|') {
if (!isset($q2subqInfo[$questionNum])) {
Expand Down Expand Up @@ -4137,7 +4154,6 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
}
$ansList = ",'answers':{ " . implode(",",$answers) . "}";
}

// Set mappings of variable names to needed attributes
$varInfo_Code = array(
'jsName_on'=>$jsVarName_on,
Expand All @@ -4164,7 +4180,6 @@ public function setVariableAndTokenMappingsForExpressionManager($surveyid,$force
'rowdivid'=>(is_null($rowdivid) ? '' : $rowdivid),
'onlynum'=>$onlynum,
);

$this->questionSeq2relevance[$questionSeq] = array(
'relevance'=>$relevance,
'grelevance'=>$grelevance,
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/questionHelper.php
Expand Up @@ -291,7 +291,7 @@ public static function getAttributesDefinitions()
);

self::$attributes["em_validation_q"] = array(
"types"=>":;ABCDEFKMNOPQRSTU",
"types"=>":;ABCDEFHKMNOPQRSTU"."L!", // separate question with REAL subqs (in EM) and with FALSE subsq (where subqs are answer …)
'category'=>gT('Logic'),
'sortorder'=>200,
'inputtype'=>'textarea',
Expand All @@ -301,7 +301,7 @@ public static function getAttributesDefinitions()
);

self::$attributes["em_validation_q_tip"] = array(
"types"=>":;ABCDEFKMNOPQRSTU",
"types"=>":;ABCDEFHKMNOPQRSTU"."L!", // separate question with subqs (in EM) and without
'category'=>gT('Logic'),
'sortorder'=>210,
'inputtype'=>'textarea',
Expand Down
Expand Up @@ -11,26 +11,26 @@
<label for="othertext<?php echo $name; ?>" class="sr-only">
<?php echo $label; ?>
</label>
<div class="form-group text-item other-text-item">
<?php
echo \CHtml::textField("{$name}other",$value,array(
'id' => "{$name}othertext",
'style' => $display,
'id' => "othertext{$name}",
'class'=>"form-control",
'aria-labelledby' => "answer{$name}-oth-",
));
?>

</div>
<script>
if( $("#answer<?php echo $name; ?>").val() != "-oth-" ){
$("#othertext<?php echo $name; ?>").hide();
}

$(document).on("change","#answer<?php echo $name; ?>", function(){
if($("#answer<?php echo $name; ?>").val() != "-oth-"){
$("#<?php echo $name; ?>othertext").hide();
$("#<?php echo $name; ?>othertext").val("").trigger("keyup");
$("#othertext<?php echo $name; ?>").hide();
$("#othertext<?php echo $name; ?>").val("").trigger("keyup");
}else{
$("#<?php echo $name; ?>othertext").show();
$("#<?php echo $name; ?>othertext").focus();
$("#othertext<?php echo $name; ?>").show();
$("#othertext<?php echo $name; ?>").focus();
}
});
</script>
Expand Down
Expand Up @@ -39,8 +39,9 @@
class="form-control <?php echo $kpclass; ?> input-sm"
id="answer<?php echo $name; ?>othertext"
name="<?php echo $name; ?>other"
title="<?php eT('Other'); ?>" <?php echo $answer_other;?>
onkeyup="if($.trim($(this).val())!=''){ $('#SOTH<?php echo $name; ?>').click(); }; <?php echo $oth_checkconditionFunction; ?>",
title="<?php eT('Other'); ?>"
<?php echo $answer_other;?>
onkeyup="if($.trim($(this).val())!=''){ $('#SOTH<?php echo $name; ?>').click(); };"
aria-labelledby="label-id-<?php echo $name; ?>"
/>
</div>
Expand Down

0 comments on commit ea543a5

Please sign in to comment.