Shino
Shino

Reputation: 99

Extjs - Ext.Window: Having trouble passing values to new window

I'm passing data to a new Window. I know the data is getting there b/c I can see it in the debugger before it hits the show(). There are form fields on the new window and they are not getting populated with the values passed in. I've also tried the afterrender method which you will see in there, but it did not even see my component. Window pops up and renders fine. But nothing populates.

Here's what I'm doing:

initComponent: function() { 
   var me = this;
    Ext.applyIf(me, {
        items: [
        {
            xtype: 'form',
            padding : 5,
            itemId: '',
            title: 'form',
            layout  : {
              type    : 'table',
              columns : 3
            },
            defaults : {
              padding : 5
            },
            items: [
            {
                xtype : 'hiddenfield',
                value : this.aId,
                name : 'announcementId',
                id : 'announcementId',
                text: 'Id',
                width: 1,
                hidden: true,
                colspan : 3
            },
            {
                xtype: 'textareafield',
                grow: false,
                width : 650,
                name: 'announcement',
                id: 'announcement',
                fieldLabel: bundle.getMsg('adminform.label.message'),
                anchor: '100%',
                // This does not populate.
                value : this.message,
                colspan : 3
            },
...
...
            }],
            listeners : {
              afterRender : function() {
                debugger;
                // Could not find the component.
                Ext.getCmp('announcement').value = this.message;
              }
            },
            viewConfig: {
              border: true,
              enableTextSelection: true
            }
        }
    ]
    });
    me.callParent(arguments);
},

// This method does go off.
showWithData : function(aId, message, start, end, active) {
  debugger;
  this.aId = aId;
  this.message = message;
  this.start = start;
  this.end = end;
  this.active = active;
  this.show();
}

Any help would be appreciated. Thanks!

Upvotes: 0

Views: 1782

Answers (1)

rixo
rixo

Reputation: 25031

initComponent is called only once, and that's when the component is created. And that's before you set all your properties...

You should use the form setValues method to update the form's data. So your method should look like this:

showWithData : function(aId, message, start, end, active) {
    var formPanel = this.down('form'), // get a ref to the FormPanel component
        form = formPanel.getForm();

    form.setValues({
        announcementId: aId,
        announcement: message,
        ...
    });

    this.show();
}

Upvotes: 2

Related Questions