EasyUI Forum
May 20, 2024, 05:09:17 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: Easyui-numberbox input how to start letter whith 0 or 00 or 00000...  (Read 9551 times)
zh_CN
Newbie
*
Posts: 32



View Profile Email
« on: May 20, 2014, 06:37:42 AM »

When i input 0001, then it changed 1.
« Last Edit: May 20, 2014, 07:56:00 PM by zh_CN » Logged

From the great China
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 20, 2014, 08:03:40 AM »

You need to custom the 'formatter' and 'parser' functions. Try the code below:
Code:
<input class="easyui-numberbox" value="1" data-options="
formatter:function(v){
var s = new String(v||'');
var prefix = '';
for(var i=0; i<4-s.length; i++){
prefix += '0';
}
return prefix+s;
},
parser:function(s){
return parseInt(s)||0;
}
">
Logged
zh_CN
Newbie
*
Posts: 32



View Profile Email
« Reply #2 on: May 20, 2014, 07:22:17 PM »

You need to custom the 'formatter' and 'parser' functions. Try the code below:
Code:
<input class="easyui-numberbox" value="1" data-options="
formatter:function(v){
var s = new String(v||'');
var prefix = '';
for(var i=0; i<4-s.length; i++){
prefix += '0';
}
return prefix+s;
},
parser:function(s){
return parseInt(s)||0;
}
">

I use:
Code:
$("#end_number").numberbox({
    required:true
    formatter:function(v){
var s = new String(v||'');
var prefix = '';
for(var i=0; i<4-s.length; i++){
prefix += '0';
}
return prefix+s;
},
parser:function(s){
return parseInt(s)||0;
}
});


how can only input number(0-9 like  001 or 05 or 0009 or 0000010 ...),

The 0 number is not fixed, thant can start with 0 or 00..?


My english is poor, so you maybe know wrong what i mean in to top(for(var i=0; i<4-s.length; i++)).

 thanks!
« Last Edit: May 20, 2014, 07:43:27 PM by zh_CN » Logged

From the great China
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!