From 2e039e15c201d357e02b9f5917fab6832560e492 Mon Sep 17 00:00:00 2001 From: Gabriel Jenik Date: Mon, 12 Jan 2015 18:20:13 -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 | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/scripts/survey_runtime.js b/scripts/survey_runtime.js index 66066a4f199..11676afd4b5 100644 --- a/scripts/survey_runtime.js +++ b/scripts/survey_runtime.js @@ -147,6 +147,7 @@ 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 @@ -154,6 +155,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) { @@ -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(','); @@ -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';