Skip to content

Commit

Permalink
Fixed issue #6859: Integer values displayed as floating point numbers
Browse files Browse the repository at this point in the history
Fixed issue: Can add dot on integer only numerci question type
Dev: remove all ending 0 to numeric question type, and remove the . if it's at ending
Dev: TODO : move control of numeric/integer in clean external js
  • Loading branch information
Shnoulle committed Nov 20, 2012
1 parent 4ca36da commit 54616cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
3 changes: 1 addition & 2 deletions application/helpers/common_helper.php
Expand Up @@ -1718,7 +1718,6 @@ function getSIDGIDQIDAIDType($fieldcode)
}

/**
*
* @param type $iSurveyID The Survey ID
* @param type $sFieldCode Field code of the particular field
* @param type $sValue The stored response value
Expand Down Expand Up @@ -1753,11 +1752,11 @@ function getExtendedAnswer($iSurveyID, $sFieldCode, $sValue, $oLanguage)
case 'N':
if (trim($sValue)!='')
{
$sValue=rtrim($sValue,"0.");
$qidattributes = getQuestionAttributeValues($fields['qid']);
if($qidattributes['num_value_int_only'])
{
$sValue=number_format($sValue, 0, '', '');

}
}
break;
Expand Down
19 changes: 10 additions & 9 deletions application/helpers/qanda_helper.php
Expand Up @@ -3679,12 +3679,12 @@ function do_numerical($ia)
{
// Only maxlength attribute, use textarea[maxlength] jquery selector for textarea
$maximum_chars= intval(trim($aQuestionAttributes['maximum_chars']));
$maxlength= "maxlength='{$maximum_chars}' ";
$maxlength= " maxlength='{$maximum_chars}' ";
$extraclass .=" maxchars maxchars-".$maximum_chars;
}
else
{
$maxlength= "maxlength='20' ";
$maxlength= " maxlength='20' ";
}
if (trim($aQuestionAttributes['text_input_width'])!='')
{
Expand All @@ -3696,20 +3696,22 @@ function do_numerical($ia)
$tiwidth=10;
}

if (trim($aQuestionAttributes['num_value_int_only'])==1 && is_float($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]))
$fValue=rtrim($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]],'0.');// Remove ending . and extra 0
if (trim($aQuestionAttributes['num_value_int_only'])==1 && is_numeric($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]))
{
$acomma="";
$extraclass .=" integeronly";
$answertypeclass = " integeronly";
$answertypeclass .= " integeronly";
$fValue=number_format($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]], 0, '', '');
$integeronly=1;
}
else
{
$acomma=getRadixPointData($thissurvey['surveyls_numberformat']);
$acomma = $acomma['seperator'];
$fValue=$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]];

$integeronly=0;
}

$sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeperator = $sSeperator['seperator'];
$fValue = str_replace('.',$sSeperator,$fValue);
Expand All @@ -3718,7 +3720,7 @@ function do_numerical($ia)
{
includeKeypad();
$extraclass .=" inputkeypad";
$answertypeclass = "num-keypad";
$answertypeclass .= " num-keypad";
}
else
{
Expand All @@ -3728,13 +3730,12 @@ function do_numerical($ia)
$answer = "<p class='question answer-item text-item numeric-item {$extraclass}'>"
. " <label for='answer{$ia[1]}' class='hide label'>{$clang->gT('Answer')}</label>\n$prefix\t"
. "<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)' "
. "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

0 comments on commit 54616cb

Please sign in to comment.