Skip to content

Commit

Permalink
Fixed issue #10830 : thousand separator break slider in some condition
Browse files Browse the repository at this point in the history
Fixed issue #09876: Different bogus with thousand seperator
Dev: use the JS only fix to be more quick
Dev: adapt the js to apply only to .thousandsseparator input.numeric
  • Loading branch information
Shnoulle committed Mar 25, 2016
1 parent cbea54e commit da7da69
Showing 1 changed file with 43 additions and 58 deletions.
101 changes: 43 additions & 58 deletions scripts/numerical_input.js
@@ -1,6 +1,15 @@
$(document).on('submit','#limesurvey', function(){
$('.thousandsseparator input.numeric').each(function(){
var re = new RegExp(escapeRegExp(thousandsSep()), 'g');
$(this).val($(this).val().replace(re, ''));
});
});
$(document).on('keyup','.thousandsseparator input.numeric', function(){
ExprMgr_process_relevance_and_tailoring('onchange', $(this).attr('name'), $(this).attr('type'));
});

$(document).ready(function () {
if (typeof LEMradix === 'undefined') { return; }

if (LEMradix == ',')
{
var centsSep = ',';
Expand All @@ -11,45 +20,48 @@ $(document).ready(function () {
var centsSep = '.';
var thousandsSep = ',';
}

var selector = '.thousandsseparator input.numeric, input.integeronly, .numberonly input[type=text]';
$(selector).unbind('keydown');
$('input.numeric, .numberonly input[type=text]').priceFormat({
'centsSeparator' : centsSep,
'thousandsSeparator' : thousandsSep,
'centsLimit' : 2,
'prefix' : '',
'allowNegative' : true
});
$('input.integeronly').priceFormat({
'centsSeparator' : centsSep,
'thousandsSeparator' : thousandsSep,
'centsLimit' : 0,
'prefix' : '',
'allowNegative' : true
});


$(selector).bind('keyup', custom_checkconditions);
// Initialize LEM tabs first.
LEMsetTabIndexes();

$(selector).removeAttr('onkeyup');
$('form#limesurvey').bind('submit', {'selector': selector}, ls_represent_all );

// Replace the LEMval
window.orgLEMval = window.LEMval;
window.LEMval = function (alias) {

var varName = LEMalias2varName[alias.split(".", 1)];
var attr = LEMvarNameAttr[varName];
if (attr.onlynum == 1)
if (attr.onlynum == 1 && $('#' + attr.jsName_on).closest(".numeric-item").length && $('#' + attr.jsName_on).closest(".numeric-item").hasClass("thousandsseparator")) // Do it only if value is in page
{
return ls_represent($('#' + attr.jsName_on).val());
}
return orgLEMval(alias);
};
$('.thousandsseparator input.numeric').not('.integeronly').each(function(){
if($(this).val()!="")
{

var newVal=$(this).val();
if(centsSep == ',')
newVal=newVal.split(',').join('.');
newVal=newVal*1;
newVal=Math.round(newVal * 100); // What for 0 .....
$(this).val(newVal);
}
$(this).unbind('keydown').removeAttr('onkeyup').priceFormat({
'centsSeparator' : centsSep,
'thousandsSeparator' : thousandsSep,
'centsLimit' : 2,
'prefix' : '',
'allowNegative' : true
}).trigger("keyup");
});
$('.thousandsseparator input.integeronly').unbind('keydown').removeAttr('onkeyup').priceFormat({
'centsSeparator' : centsSep,
'thousandsSeparator' : thousandsSep,
'centsLimit' : 0,
'prefix' : '',
'allowNegative' : true
}).trigger("keyup");
LEMsetTabIndexes();

});


/*
This function is called on key down and checks the value when tab has been pressed.
(Replaces LEMsetTabIndexes and the function bindings it contains).
Expand All @@ -62,33 +74,14 @@ function custom_tab(e)
}
}


/*
This function is called after priceformat has applied its layouting.
*/
function custom_checkconditions(evt_type)
{
evt_type = typeof evt_type !== 'undefined' ? evt_type : 'onchange';

// We get the value.

// var val = $(this).attr('value');
// var pos = $(this).caret();
// $(this).attr('value', ls_represent(val));
ExprMgr_process_relevance_and_tailoring(evt_type, $(this).attr('name'), $(this).attr('type'));
// $(this).attr('value', val);
// $(this).caret(pos);

}

function centsSep()
{
return LEMradix;
}

function thousandsSep()
{
if (LEMradix == ',')
if (LEMradix == ',')
{
return '.';
}
Expand All @@ -99,7 +92,7 @@ function thousandsSep()
}

/*
Takes a value from a box and returns the representation limesurvey uses to save it.
Takes a value from a box and returns the representation for EM.
*/
function ls_represent(value)
{
Expand All @@ -118,17 +111,9 @@ function ls_represent(value)
{
return value;
}

}

function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}

function ls_represent_all(e)
{
$(e.data.selector).each(function () {
$(this).attr('value', ls_represent($(this).attr('value')));

});
}

0 comments on commit da7da69

Please sign in to comment.