Reputation: 4059
Here is the following form and i wanna access form`s apply button inside the form without using Ext.getCmp() and defining an id for the button:
{xtype : 'form',
url : 'index.php/submitform',
trackResetOnLoad : true,
id : 'generalprofilebasicinformation'+ this.getId(),
listeners : {
//is fired when the form is dirty(field values are modified)
dirtychange : {
fn : function(sm) {
//Here Is my problem:
//How to access to Apply button or any other buttons defined inside the form???
var applyButton = this.Button;
applyButton.enable();}}},
buttons : [{
text : 'Apply',
formBind : true, // only
// enabled
// once the
// form is
// valid
disabled : true,} ]}
Upvotes: 2
Views: 13075
Reputation: 447
You can use a controller to listen for the 'dirtychange' event fired by this form.
//controller init
init: function() {
this.control({
'form': {
dirtychange: function(form) {
var button = form.owner.query('button[text=Apply]');
button[0].enable();
}
}
});
}
The answer darren gave will certainly work, this just utilizes component queries to give you a different way to reach and control components. If you wanted to enable a series of buttons within the form, for example, you could remove the 'text=Apply' and an array of all the forms buttons will be returned.
Upvotes: 2
Reputation: 15673
Agreed with jthirau - definitely use component query.
Another way to do what you are doing is to simply add a button handler. This goes right on the button config:
handler:function(){
//do something
}
Upvotes: 1
Reputation: 2830
Use a constructor and then you can create the button inside it and then have a reference to it in your form. Once you have the reference in the form, you can then retrieve it from the listener you have there. Would look like this:
contructor: function(config) {
this.button = new Ext.Button({
// Provide your button config here
});
}
listeners: {
dirtychange: function(sm) {
this.button.enable();
}
}
That should work without using Ext.getCmp()
Upvotes: 1