Skip to content

Commit

Permalink
Fixed issue #05524: matrix (text) + additionl option only numbers not…
Browse files Browse the repository at this point in the history
… working correct

Dev This input type now supports comma as the radix separator
Dev Made comparable to other numeric inputs - only does processing on change; and if an invalid number is detected, the field is immediately blanked
Dev Note, in 1.91, also did not have checkconditions() bound when non-numeric; so fixed that too.
  • Loading branch information
TMSWhite committed Mar 2, 2012
1 parent 3df792f commit 2f2d874
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 40 deletions.
34 changes: 31 additions & 3 deletions application/helpers/qanda_helper.php
Expand Up @@ -5374,6 +5374,8 @@ function do_array_multitext($ia)
}

$checkconditionFunction = "checkconditions";
$sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']);
$sSeperator = $sSeperator['seperator'];

$defaultvaluescript = "";
$qquery = "SELECT other FROM {{questions}} WHERE qid={$ia[0]} AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."'";
Expand Down Expand Up @@ -5684,17 +5686,43 @@ function do_array_multitext($ia)
}
if($show_totals == 'col' || $show_totals = 'both' || $grand_total == true)
{
$answer .= "\t\t<tr class=\"total information-list\">$row_head";
$answer .= "\t\t<tr class=\"total\">$row_head";
for( $a = 0; $a < count($labelcode) ; ++$a )
{
$answer .= str_replace(array('[[ROW_NAME]]','[[INPUT_WIDTH]]') , array(strip_tags($answertext),$inputwidth) , $col_total);
}
};
$answer .= str_replace(array('[[ROW_NAME]]','[[INPUT_WIDTH]]') , array(strip_tags($answertext),$inputwidth) , $grand_total)."\n\t\t</tr>\n";
}
$answer .= "\t</tbody>\n</table>\n";
if(!empty($q_table_id))
{
$answer .= "\n<script type=\"text/javascript\">new multi_set('$q_table_id');</script>\n";
if ($aQuestionAttributes['numbers_only']==1)
{
$radix = $sSeperator;
}
else {
$radix = 'X'; // to indicate that should not try to change entered values
}
$answer .= "\n<script type=\"text/javascript\">new multi_set('$q_table_id','$radix');</script>\n";
}
else
{
$addcheckcond = <<< EOD
<script type="text/javascript">
<!--
$(document).ready(function()
{
$('#question{$ia[0]} :input:visible:enabled').each(function(index){
$(this).bind('change',function(e) {
checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
return true;
})
})
})
// -->
</script>
EOD;
$answer .= $addcheckcond;
}
}
else
Expand Down
67 changes: 30 additions & 37 deletions scripts/survey_runtime.js
Expand Up @@ -537,14 +537,15 @@ function std_onsubmit_handler()
// ==========================================================
// totals

function multi_set(ids)
function multi_set(ids,_radix)
{
//quick ie check
var ie=(navigator.userAgent.indexOf("MSIE")>=0)?true:false;
//match for grand
var _match_grand = new RegExp('grand');
//match for total
var _match_total = new RegExp('total');
var radix = _radix; // comma, period, X (for not using numbers only)
//main function (obj)
//id = wrapper id
function multi_total(id)
Expand Down Expand Up @@ -605,7 +606,7 @@ function multi_set(ids)
_bits[_counter].push(_tdin);
//set key board actions
_tdin.onkeydown = _in_key;
_tdin.onkeyup = calc;
_tdin.onchange = calc;
//check for total and grand total
if(_td[_a].className && _td[_a].className.match(_match_total,'ig'))
{
Expand Down Expand Up @@ -746,6 +747,16 @@ function multi_set(ids)
e=(e)?e:event;
var el=e.target||e.srcElement;
var _id=el.getAttribute(ie ? 'className' : 'class');

// eliminate bad numbers
_aval=el.value;
if (radix===',') {
_aval = _aval.split(',').join('.');
}
if (radix!=='X' && _aval != parseFloat(_aval)) {
el.value = "";
}

//vert_[id] horo_[id] in class trigger vert or horo calc on row[id]
if(_id.match('vert_','ig'))
{
Expand Down Expand Up @@ -804,24 +815,13 @@ function multi_set(ids)
}
else if(_bits[i][vid].value)
{
if(_bits[i][vid].value.match('-','ig'))
{
var _iklebit = _bits[i][vid].value.replace('-','','ig');
//alert(iklebit);
if(_iklebit)
{
qt -=(_iklebit * 1);
}
}
else
{
qt += (_bits[i][vid].value * 1);
}

// }
// else
// {
// _bits[i][vid].value = '0';
_aval=_bits[i][vid].value;
if (radix===',') {
_aval = _aval.split(',').join('.');
}
if (_aval == parseFloat(_aval)) {
qt += +_aval;
}
};
};

Expand All @@ -847,23 +847,13 @@ function multi_set(ids)
}
else if(_bits[hid][i].value)
{
if(_bits[hid][i].value.match('-','ig'))
{
var _iklebit = _bits[hid][i].value.replace('-','','ig');
//alert(_iklebit);
if(_iklebit)
{
qt -= (_iklebit * 1);
}
}
else
{
qt += (_bits[hid][i].value * 1);
}
// }
// else
// {
// _bits[hid][i].value = '0';
_aval=_bits[hid][i].value;
if (radix===',') {
_aval = _aval.split(',').join('.');
}
if (_aval == parseFloat(_aval)) {
qt += +_aval;
}
};
};
};
Expand Down Expand Up @@ -916,6 +906,9 @@ function multi_set(ids)
case 110:
case 109:
case 189:
case 188:
if (radix===',' && e.keyCode == 190) { return false; }
if (radix==='.' && e.keyCode == 188) { return false; }
return(e.keyCode);
default:
//alert(e.keyCode);
Expand Down

0 comments on commit 2f2d874

Please sign in to comment.