Skip to content

Commit

Permalink
Revert "Dev: Start fix issue #8217: "Numerical Input" question valida…
Browse files Browse the repository at this point in the history
…tion only client side"

Dev: This reverts commit f1712f4.
Dev: To be on own repo before testing
  • Loading branch information
Shnoulle committed Oct 10, 2013
1 parent f1712f4 commit 5743eb0
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 188 deletions.
78 changes: 71 additions & 7 deletions application/helpers/SurveyRuntimeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -975,14 +975,78 @@ function run($surveyid,$args) {

// the runonce element has been changed from a hidden to a text/display:none one
// in order to workaround an not-reproduced issue #4453 (lemeur)
echo "<input type='text' id='runonce' value='0' style='display: none;'/>";

// lemradix and var for LemRadix
$sLemRadixVarScript=" LEMradix='" . $radix . "';\n"
." numRegex = new RegExp('[^-' + LEMradix + '0-9]','g');\n"
." intRegex = new RegExp('[^-0-9]','g');\n";
Yii::app()->clientScript->registerScript('LemRadixVarScript',$sLemRadixVarScript,CClientScript::POS_HEAD);
echo "<input type='text' id='runonce' value='0' style='display: none;'/>
<!-- JAVASCRIPT FOR CONDITIONAL QUESTIONS -->
<script type='text/javascript'>
<!--\n";

echo "var LEMradix='" . $radix . "';\n";
echo "var numRegex = new RegExp('[^-' + LEMradix + '0-9]','g');\n";
echo "var intRegex = new RegExp('[^-0-9]','g');\n";

print <<<END
function fixnum_checkconditions(value, name, type, evt_type, intonly)
{
newval = new String(value);
if (typeof intonly !=='undefined' && intonly==1) {
newval = newval.replace(intRegex,'');
}
else {
newval = newval.replace(numRegex,'');
}
if (LEMradix === ',') {
newval = newval.split(',').join('.');
}
if (newval != '-' && newval != '.' && newval != '-.' && newval != parseFloat(newval)) {
newval = '';
}
displayVal = newval;
if (LEMradix === ',') {
displayVal = displayVal.split('.').join(',');
}
if (name.match(/other$/)) {
$('#answer'+name+'text').val(displayVal);
}
$('#answer'+name).val(displayVal);
if (typeof evt_type === 'undefined')
{
evt_type = 'onchange';
}
checkconditions(newval, name, type, evt_type);
}
function checkconditions(value, name, type, evt_type)
{
if (typeof evt_type === 'undefined')
{
evt_type = 'onchange';
}
if (type == 'radio' || type == 'select-one')
{
$('#java'+name).val(value);
}
else if (type == 'checkbox')
{
if ($('#answer'+name).is(':checked'))
{
$('#java'+name).val('Y');
} else
{
$('#java'+name).val('');
}
}
else if (type == 'text' && name.match(/other$/))
{
$('#java'+name).val(value);
}
ExprMgr_process_relevance_and_tailoring(evt_type,name,type);
END;
print <<<END
}
// -->
</script>
END;
$showpopups=Yii::app()->getConfig('showpopups');
//Display the "mandatory" message on page if necessary
if (!$showpopups && $stepInfo['mandViolation'] && $okToShowErrors)
Expand Down
8 changes: 4 additions & 4 deletions application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1726,10 +1726,10 @@ function getExtendedAnswer($iSurveyID, $sFieldCode, $sValue, $oLanguage)
$sValue=rtrim(rtrim($sValue,"0"),".");
}
$qidattributes = getQuestionAttributeValues($fields['qid']);
# if($qidattributes['num_value_int_only'])
# {
# $sValue=number_format($sValue, 0, '', '');
# }
if($qidattributes['num_value_int_only'])
{
$sValue=number_format($sValue, 0, '', '');
}
}
break;
case "L":
Expand Down
120 changes: 9 additions & 111 deletions application/helpers/expressions/em_manager_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1304,33 +1304,6 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
// Default validation for question type
switch ($type)
{
case 'N': //NUMERICAL QUESTION TYPE
// TODO : same for multinumeric
if ($hasSubqs) {
$subqs = $qinfo['subqs'];
$sq_equs=array();
foreach($subqs as $sq)
{
$sq_name = ($this->sgqaNaming)?$sq['rowdivid'].".NAOK":$sq['varName'].".NAOK";
if(($qinfo['mandatory']=='Y')){
$sq_equs[] = '(fixnum('.$sq_name.')== '.$sq_name.')';
}else{
$sq_equs[] = '(fixnum('.$sq_name.')== '.$sq_name.' || is_empty('.$sq_name.') )';
}
}
if (!isset($validationEqn[$questionNum]))
{
$validationEqn[$questionNum] = array();
}
$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'default',
'class' => 'default',
'eqn' => implode(' and ',$sq_equs),
'qid' => $questionNum,
);
}
break;
case 'R':
if ($hasSubqs) {
$subqs = $qinfo['subqs'];
Expand Down Expand Up @@ -1954,72 +1927,6 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
$max_num_value_n='';
}

// num_value_int_only
// Validation fixnum(sqN)==int(fixnum(sqN)) : fixnum or not fix num ..... 10.00 == 10
if (isset($qattr['num_value_int_only']) && trim($qattr['num_value_int_only']) == "1")
{
$num_value_int_only="1";
if ($hasSubqs) {
$subqs = $qinfo['subqs'];
$sq_names = array();
$subqValidEqns = array();
foreach ($subqs as $sq) {
$sq_name = NULL;
switch ($type)
{
case 'N': //NUMERICAL QUESTION TYPE
if(($qinfo['mandatory']=='Y')){
if ($this->sgqaNaming)
{
$sq_name = '(intval(fixnum('.$sq['rowdivid'].'.NAOK))== fixnum('.$sq['rowdivid'].'.NAOK))';
}
else
{
$sq_name = '(intval(fixnum('.$sq['varName'].'.NAOK))== fixnum('.$sq['varName'].'.NAOK))';
}
}else{
if ($this->sgqaNaming)
{
$sq_name = '(intval(fixnum('.$sq['rowdivid'].'.NAOK))== fixnum('.$sq['rowdivid'].'.NAOK) || is_empty('.$sq['rowdivid'].'.NAOK))';
}
else
{
$sq_name = '(intval(fixnum('.$sq['varName'].'.NAOK))== fixnum('.$sq['varName'].'.NAOK) || is_empty('.$sq['varName'].'.NAOK))';
}
}
break;
default:
break;
}
if (!is_null($sq_name)) {
$sq_names[] = $sq_name;
$subqValidEqns[$subqValidSelector] = array(
'subqValidEqn' => $sq_name,
'subqValidSelector' => $subqValidSelector,
);
}
}
if (count($sq_names) > 0) {
if (!isset($validationEqn[$questionNum]))
{
$validationEqn[$questionNum] = array();
}
$validationEqn[$questionNum][] = array(
'qtype' => $type,
'type' => 'num_value_int_only',
'class' => 'value_integer',
'eqn' => implode(' && ', $sq_names),
'qid' => $questionNum,
'subqValidEqns' => $subqValidEqns,
);
}
}
}
else
{
$num_value_int_only='';
}

// min_num_value
// Validation:= sum(sq1,...,sqN) >= value (which could be an expression).
if (isset($qattr['min_num_value']) && trim($qattr['min_num_value']) != '')
Expand Down Expand Up @@ -2650,9 +2557,6 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
// Default validation qtip without attribute
switch ($type)
{
case 'N':
$qtips['default']=$this->gT("Only numbers may be entered in this field.");
break;
case 'R':
$qtips['default']=$this->gT("All your answers must be different.");
break;
Expand Down Expand Up @@ -2703,12 +2607,6 @@ public function _CreateSubQLevelRelevanceAndValidationEqns($onlyThisQseq=NULL)
"{if(!is_empty($_minV) && !is_empty($_maxV) && ($_minV) != ($_maxV), sprintf('".$this->gT("Each answer must be between %s and %s")."', fixnum($_minV), fixnum($_maxV)), '')}";
}

// integer for numeric
if ($num_value_int_only!='')
{
$qtips['value_integer']=$this->gT("Only integer value");
}

// min/max value for each numeric entry - for multi-flexible question type
if ($multiflexible_min!='' || $multiflexible_max!='')
{
Expand Down Expand Up @@ -7835,17 +7733,17 @@ static function ProcessCurrentResponses()
}
$aDateFormatData=getDateFormatDataForQID($aAttributes[$qid],$LEM->surveyOptions);
$oDateTimeConverter = new Date_Time_Converter($value, $aDateFormatData['phpdate']);
$value=$oDateTimeConverter->convert("Y-m-d H:i"); // TODO : control if inverse function original value
$value=$oDateTimeConverter->convert("Y-m-d H:i");
}
break;
# case 'N': //NUMERICAL QUESTION TYPE
# case 'K': //MULTIPLE NUMERICAL QUESTION
# if (trim($value)=="") {
# $value = "";
# }
# else {
# $value = sanitize_float($value);
# }
case 'N': //NUMERICAL QUESTION TYPE
case 'K': //MULTIPLE NUMERICAL QUESTION
if (trim($value)=="") {
$value = "";
}
else {
$value = sanitize_float($value);
}
break;
case '|': //File Upload
if (!preg_match('/_filecount$/', $sq))
Expand Down
7 changes: 5 additions & 2 deletions application/helpers/qanda_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,7 @@ function do_numerical($ia)
$answertypeclass .= " integeronly";
if(is_numeric($fValue))
{
//$fValue=number_format($fValue, 0, '', '');
$fValue=number_format($fValue, 0, '', '');
}
$integeronly=1;
}
Expand All @@ -3389,7 +3389,6 @@ function do_numerical($ia)

$sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeparator = $sSeparator['separator'];
$fValue = rtrim(trim($fValue,"0"),".");
$fValue = str_replace('.',$sSeparator,$fValue);

if ($thissurvey['nokeyboard']=='Y')
Expand All @@ -3408,6 +3407,10 @@ function do_numerical($ia)
. "<input class='text {$answertypeclass}' type=\"text\" size=\"$tiwidth\" name=\"$ia[1]\" title=\"".$clang->gT('Only numbers may be entered in this field.')."\" "
. "id=\"answer{$ia[1]}\" value=\"{$fValue}\" onkeyup=\"{$checkconditionFunction}(this.value, this.name, this.type,'onchange',{$integeronly})\" "
. " {$maxlength} />\t{$suffix}\n</p>\n";
if ($aQuestionAttributes['hide_tip']==0)
{
$answer .= "<p class=\"tip\">".$clang->gT('Only numbers may be entered in this field.')."</p>\n";
}
// --> END NEW FEATURE - SAVE

$inputnames[]=$ia[1];
Expand Down
64 changes: 0 additions & 64 deletions scripts/survey_runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,70 +106,6 @@ function needConfirmHandler(){
});
});
}
/**
* checkconditions : javascript function attach to some element
* Launch ExprMgr_process_relevance_and_tailoring with good value
*/
function checkconditions(value, name, type, evt_type)
{
if (typeof evt_type === 'undefined')
{
evt_type = 'onchange';
}
if (type == 'radio' || type == 'select-one')
{
$('#java'+name).val(value);
}
else if (type == 'checkbox')
{
if ($('#answer'+name).is(':checked'))
{
$('#java'+name).val('Y');
} else
{
$('#java'+name).val('');
}
}
else if (type == 'text' && name.match(/other$/))
{
$('#java'+name).val(value);
}
ExprMgr_process_relevance_and_tailoring(evt_type,name,type);
}
/**
* fixnum_checkconditions : javascript function attach to some element
* Update the answer of the user to be numeric and launch checkconditions
*/
function fixnum_checkconditions(value, name, type, evt_type, intonly)
{
// newval = new String(value);
// if (typeof intonly !=='undefined' && intonly==1) {
// newval = newval.replace(intRegex,'');
// }
// else {
// newval = newval.replace(numRegex,'');
// }
// if (LEMradix === ',') {
// newval = newval.split(',').join('.');
// }
// if (newval != '-' && newval != '.' && newval != '-.' && newval != parseFloat(newval)) {
// newval = '';
// }
// displayVal = newval;
// if (LEMradix === ',') {
// displayVal = displayVal.split('.').join(',');
// }
// if (name.match(/other$/)) {
// $('#answer'+name+'text').val(displayVal);
// }
// $('#answer'+name).val(displayVal);

// if (typeof evt_type === 'undefined')
// {
// evt_type = 'onchange';
// }
checkconditions(value, name, type, evt_type);
}

// Set jquery-ui to LS Button
function navbuttonsJqueryUi(){
Expand Down

0 comments on commit 5743eb0

Please sign in to comment.