EasyUI Forum
May 22, 2024, 05:17:48 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: NumberBox input how to replace dot with a comma  (Read 11809 times)
peterg
Newbie
*
Posts: 3


View Profile
« on: February 12, 2013, 04:30:20 AM »

Hi, i try to use this great project in a German business app.

The NumberBox works fine for display the numbers as we needed.
By typing in the <input> field with a German keyboard we have a comma "," on the keyboard nunberblock.

How to chance it to accept the comma at type in and replace(',' , '.') for use in code. 
it is necessary to use jQuery EasyUI in most European countries.

ahead thanks for a hint.

Peter

Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 12, 2013, 05:52:41 PM »

To allow inputting comma, rebind the 'keypress.numberbox' event for the input element.
Code:
<input id="nn" class="easyui-numberbox" data-options="decimalSeparator:','">
Code:
$('#nn').numberbox().unbind('keypress.numberbox').bind('keypress.numberbox',function(e){
if (e.which == 45){ //-
if ($(this).val().indexOf('-') == -1){
return true;
} else {
return false;
}
} if (e.which == 46 || e.which == 44) { //.,
if ($(this).val().indexOf('.') == -1){
return true;
} else {
return false;
}
}
else if ((e.which >= 48 && e.which <= 57 && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8) {
return true;
} else if (e.ctrlKey == true && (e.which == 99 || e.which == 118)) {
return true;
} else {
return false;
}
});
Logged
peterg
Newbie
*
Posts: 3


View Profile
« Reply #2 on: February 13, 2013, 01:28:41 PM »

thanks it work.

i place the code in  $(document).ready(function() 
Code:
    $(document).ready(function() {
$('#nn').numberbox().unbind('keypress.numberbox').bind('keypress.numberbox',function(e){
if (e.which == 45){ //-
if ($(this).val().indexOf('-') == -1){
return true;
} else {
return false;
}
} if (e.which == 46 || e.which == 44) { //.,
if ($(this).val().indexOf('.') == -1){
return true;
} else {
return false;
}
}
else if ((e.which >= 48 && e.which <= 57 && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8) {
return true;
} else if (e.ctrlKey == true && (e.which == 99 || e.which == 118)) {
return true;
} else {
return false;
}
    });
   });

it don’t work in "easyui-layout" loadet files.
called with
Code:
function center37(){ $('#p').panel('refresh','include/NumberBox.php'); }

I see a lot to learn for me.

can i have a hint please
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!