Search code examples
formsextjsformpanel

Unable to call getValues() on an Ext Js FormPanel on initialization of a container Panel


I have an Ext Js panel that I am adding to my main TabPanel. The panel I am adding contains a FormPanel as one of it's items and inside the FormPanel I have a Name field. What I want to do is change the name of the Tab based on the name in the form field.

The problem is that if I call the FormPanel's getForm().getValues() inside of the panel's initComponent, I get the following javascript error:

Uncaught TypeError: Cannot read property 'dom' of undefined

If I do this outside of initComponent (e.g. on a button press) everything works fine. After doing some testing, I think the issue is that the FormPanel isn't actually rendered yet (and thus the dom doesn't exist), getValues() fails. However, I can't seem to figure out a way to get my FormPanel's values from the Panel on load.

I tried to listen for events. I tried:

this.detailForm.on('afterrender', function () { alert('test'); });

but doing this showed that AfterRender is called prior to the form actually being rendered (it's not visible on the screen). Changing the alert to my custom function handler produces the previous dom exception. I attempted to use the activate and enable events instead of afterrender, but even though the API says that FormPanel fires those events, the alert('test') never gets called.

I can't seem to find any way for my panel to get the inner FormPanel's values upon loading my panel. Does anyone have any ideas?


Solution

  • Using getFieldValues() in place of getValues() will collect values by calling each field instance's getValue() method instead of by reading from the DOM. This should allow you to get your values regardless of the form's rendered state.