ExtJS 4 Form getValues() Tip

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));
};
VN:F [1.9.22_1171]
Rating: 7.6/10 (22 votes cast)
ExtJS 4 Form getValues() Tip, 7.6 out of 10 based on 22 ratings

8 thoughts on “ExtJS 4 Form getValues() Tip”

  1. 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?

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    1. 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…

      VN:F [1.9.22_1171]
      Rating: 4.7/5 (3 votes cast)
      1. They seem to be identical. I can’t find any differences.

        VA:F [1.9.22_1171]
        Rating: 5.0/5 (1 vote cast)
  2. 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.

    VA:F [1.9.22_1171]
    Rating: 5.0/5 (4 votes cast)
  3. Hi,
    Can any one please tell to create and run the project with sencha Ext Js in Eclipse….?

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
  4. Can i able to get both text as well as id value from combo while using form.getFieldValues() ?

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)

Leave a Reply

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *