From 10d043ba23d23f4ce3ca91a47c41ceae3b3e0e07 Mon Sep 17 00:00:00 2001 From: gabrieljenik Date: Mon, 12 Jan 2015 18:20:58 -0300 Subject: [PATCH] Fixed Issue #9241: Behaviour of numeric question type (and multi numeric) Dev Before sent to EM, treat numbers larger than 20 characters before decimal part or 10 after decimal part. --- scripts/survey_runtime.js | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/scripts/survey_runtime.js b/scripts/survey_runtime.js index 3e83eac6700..69d37a160a2 100644 --- a/scripts/survey_runtime.js +++ b/scripts/survey_runtime.js @@ -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) { @@ -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(','); @@ -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';