Another bit of undocumented goodness from yours truly. As you probably know, ExtJS4 form panel contains a very useful method: formpanel.getForm().getValues(), which lets you populate an object with form’s data. Unfortunately, string format is used for all fields, even datefields. I will show you how to easily get valid data types through an undocumented feature:
Full Source & Demo @ jsFiddle.net
If you check out the API you’ll see that there’s only 3 parameters. There’s actually a 4th one called useDataValues; here’s the underlying method signature:
getValues: function(asString, dirtyOnly, includeEmptyText, useDataValues) |
…and here’s how I use them in my project:
var process = function() { var panel = Ext.getCmp('mainPanel'); writeData(panel.down('panel[name=old]') , panel.getForm().getValues()); writeData(panel.down('panel[name=new]') , panel.getForm().getValues(false,false,false,true)); }; |
I’ve run into this problem, but using the getValues parameters you have described aren’t giving me the same results. My fields are still coming out as strings. The datefield on my form is being populated from a database record and it is being populated with the correct value. I edit that value and attempt a save, which calls getValues and assigns them back to the record. The assignment to the record is null, which is what led me to trying to see what is coming from the values, and it is indeed a string value (although a correct one). I am using ext-4.1.0-beta-2. Maybe something wrong in the beta?
Maybe there was a reason this was not documented in 4.0.7? Take a look at the source of getValues() and see if the extra param is even present in the signature of the new version…
Yes, it is there.
Then something must be wrong in the beta. See the working implementation source here:
http://docs.sencha.com/ext-js/4-0/source/Basic.html#Ext-form-Basic-method-getValues
…see how it differs from the beta; you might want to submit a bug to sencha.
They seem to be identical. I can’t find any differences.
Interesting, but I personally prefer using getFieldValues. As far as I can tell, that function does exactly what you want. As an added advantage it’s actually documented and therefore hopefully less susceptible to any implementation changes.
Hi,
Can any one please tell to create and run the project with sencha Ext Js in Eclipse….?
Can i able to get both text as well as id value from combo while using form.getFieldValues() ?