ExtJS TextField values submitted as a string instead of integer/number
I have an Ext Editor Grid with a NumberColumn. The column's editor is set to an Ext.form.TextField. This grid is populated by JSON and data is submitted as JSON.
My problem is that when the user enters a number in this col开发者_运维问答umn, it is sent as a string instead of a number. In other words, it looks like this Property: "500" and what I want is this, Property: 500.
My column definition:
new Ext.grid.NumberColumn ({
header: 'Area (ha)',
dataIndex: 'Area',
format: '0',
width: 60,
editor: new Ext.form.TextField({
allowBlank: false
})
})
And the field definition for this column:
{ name: 'Area'}
I've tried this but it does nothing:
{ name: 'Area', type: 'int' }
Any ideas? Thanks!
Found a resolution. Apparently there's a Ext.form.NumberField. It's not listed in the ExtJS documentation, I had to search for it.
It is also useful to note that in order to actually get typed values out of the form, getValues
is not suitable.
Ext.form.Basic
also has a method getFieldValues
which will return the values as you would want them when POST'ing JSON (or other non-stringified format). This will return numberfield
s as integers, checkboxes as booleans, etc.
P.S. getFieldValues
is just a wrapper around getValues
; it uses the undocumented 4th parameter of it called useDataValues
, the name of which of course is confusing, not to mention the name getFieldValues
.
精彩评论