Skip to content

Commit

Permalink
Fixed Issue #9241: Behaviour of numeric question type (and multi nume…
Browse files Browse the repository at this point in the history
…ric)

Dev Before sent to EM, treat numbers larger than 20 characters before decimal part or 10 after decimal part.
  • Loading branch information
gabrieljenik committed Jan 12, 2015
1 parent 66e2186 commit 10d043b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions scripts/survey_runtime.js
Expand Up @@ -151,6 +151,10 @@ function checkconditions(value, name, type, evt_type)
function fixnum_checkconditions(value, name, type, evt_type, intonly)
{
newval = new String(value);

/**
* If have to use parsed value.
*/
if(!bNumRealValue)
{
if (typeof intonly !=='undefined' && intonly==1) {
Expand All @@ -170,8 +174,43 @@ function fixnum_checkconditions(value, name, type, evt_type, intonly)
newval = '';
}
}

/**
* If have to fix numbers automatically.
*/
if(bFixNumAuto)
{

/**
* Work on length of the number
* Avoid numbers longer than 20 characters before the decimal separator and 10 after the decimal separator.
*/
var midval = newval;
var aNewval = midval.split('.');
var newval = '';

// Treat integer part
if (aNewval.length > 0) {
var intpart = aNewval[0];
newval = (intpart.length > 20) ? '99999999999999999999' : intpart;
}

// Treat decimal part, if there is one.
// Trim after 10th decimal if larger than 10 decimals.
if (aNewval.length > 1) {
var decpart = aNewval[1];
if (decpart.length > 10){
decpart = decpart.substr(0,10);
}
else {
decpart = aNewval[1];
}
newval = newval + "." + decpart;
}

/**
* Set display value
*/
displayVal = newval;
if (LEMradix === ',') {
displayVal = displayVal.split('.').join(',');
Expand All @@ -181,6 +220,12 @@ function fixnum_checkconditions(value, name, type, evt_type, intonly)
}
$('#answer'+name).val(displayVal);
}

console.log ("Number treated >> " + value + " >> " + newval);

/**
* Check conditions
*/
if (typeof evt_type === 'undefined')
{
evt_type = 'onchange';
Expand Down

0 comments on commit 10d043b

Please sign in to comment.