PDA

View Full Version : An auto-calculating numberfield like Excel



gregoryextjs
4 Dec 2013, 1:04 AM
Hi,


The users of my application are accountants.


They would like to have an auto-calculating numberfield like Excel.


Example : In the numberfield they put 10+20+30 and on the onblur event the numberfield displays 60.
The current numberfield does not accept calculating operators like +, -, /, *


How can the current numberfield accept calcuting operators and auto-calculate ?
If it doesn't, how can do it in a simple way ?


Thanks for your help.
Greg

gregoryextjs
4 Dec 2013, 2:24 AM
I found auto-calculating solution testing in a textfield :

blur: function(){
this.setValue(eval(this.getValue()));
}


But how to allow /*-+ chars in numberfield ?

Thanks,
Greg

willigogs
4 Dec 2013, 3:05 AM
Use a normal textfield, and apply the required regular expression (numbers, +, -) under the maskRe config:
http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.TextField-cfg-maskRe

gregoryextjs
4 Dec 2013, 4:01 AM
Thanks for your reply, but no, i can't use textfield because i need those 2 properties :

allowDecimals: true,
decimalPrecision: 2,

So i really need to keep the numberfield.
And i really don't understand how regex works. I d'ont know how to put number and /*-+ and decimalprecision and allowdecimal in regex.

Thanks,
Greg

gregoryextjs
4 Dec 2013, 4:31 AM
I solved it with


maskRe: /[0-9.\/*\-+]/,

and

blur: function(){
this.setValue(eval(this.getValue()).toFixed(2));
}

Thanks