-
28 Nov 2012 6:08 AM #1
Answered: Is there a way to get numberfield to accept decimal numbers without the leading 0?
Answered: Is there a way to get numberfield to accept decimal numbers without the leading 0?
If you type 0.7 in a numberfield it will accept the value, but if you type .7 it will clear it out. Is there a way to get this field to accept the shortened version? Obviously if the user types .7 he means 0.7.
Example code of it occurring using Sencha Touch 2.1:
Code:Ext.Viewport.add( { xtype: 'formpanel', items: [ { id: 'TestField', xtype: 'numberfield', label: 'Type .7' }, { xtype: 'button', text: 'Now Click Here', handler: function () { Ext.Msg.alert('', 'You entered: ' + Ext.getCmp('TestField').getValue() + '.'); } } ] });
-
Best Answer Posted by mitchellsimoens
Using this test:
In Chrome on the desktop I get the change and the value is .7. Testing on an ipad, the change event fires but indeed the value is set to 0.7 which is browser behavior as we aren't doing any parsing when you type. If you were to execute setValue then we do a parseFloat or when you execute getValue then we also do a parseFloat.Code:Ext.Viewport.add({ items : [ { xtype : 'numberfield', label : 'Test', listeners : { change : function () { console.log('change'); } } } ] });
-
29 Nov 2012 11:46 AM #2
Anyone?
I tried using the change event to listen for it so I can add the 0.7 on the fly, but the event doesn't even fire if you type in ".7". The field just reverts to whatever was in it previously.
-
30 Nov 2012 8:00 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,599
- Vote Rating
- 434
- Answers
- 3102
Using this test:
In Chrome on the desktop I get the change and the value is .7. Testing on an ipad, the change event fires but indeed the value is set to 0.7 which is browser behavior as we aren't doing any parsing when you type. If you were to execute setValue then we do a parseFloat or when you execute getValue then we also do a parseFloat.Code:Ext.Viewport.add({ items : [ { xtype : 'numberfield', label : 'Test', listeners : { change : function () { console.log('change'); } } } ] });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
3 Dec 2012 7:33 AM #4
It definitely does seem to be a browser specific issue. I was testing on desktop Safari, which I probably should have mentioned, and it doesn't fire the change event and resets the field instantly. Thanks for the reply and helping me understand what was going on.


Reply With Quote