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 c07ce02 commit 2e039e1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions scripts/survey_runtime.js
Expand Up @@ -147,13 +147,18 @@ function checkconditions(value, name, type, evt_type)
if($.isFunction(window.ExprMgr_process_relevance_and_tailoring ))
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 have to use parsed value.
*/
if(!bNumRealValue)
{
if (typeof intonly !=='undefined' && intonly==1) {
Expand All @@ -173,8 +178,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 @@ -184,6 +224,10 @@ function fixnum_checkconditions(value, name, type, evt_type, intonly)
}
$('#answer'+name).val(displayVal);
}

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

0 comments on commit 2e039e1

Please sign in to comment.