EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: zh_CN on May 20, 2014, 06:37:42 AM



Title: Easyui-numberbox input how to start letter whith 0 or 00 or 00000...
Post by: zh_CN on May 20, 2014, 06:37:42 AM
When i input 0001, then it changed 1.


Title: Re: Easyui-numberbox how to support the value like "0001"
Post by: stworthy 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;
}
">


Title: Re: Easyui-numberbox how to support the value like "0001"
Post by: zh_CN 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!