I’m trying to fire a custom event in sencha touch, and it seems to get added to the events that can be fired, and it appears to fire, but my listener does not seem to respond to the event.
the event is instantinated here, where this is the form body:
Ext.apply(this, {
scroll: 'vertical',
dockedItems: [ titlebar, buttonbar ],
items: [ fields ],
listeners: {
beforeactivate: function() {
var saveButton = this.down('#userFormSaveButton');
saveButton.setText('Submit');
this.addEvents('cityUpdate');
console.log('event added');
},
deactivate: function() {
this.resetForm();
}
}
});
The event is then fired here:
if (result.data != 'false' && result.data.state) {
Ext.getCmp("usersForm").fireEvent('cityUpdate', result.data.towns);
console.log('event fired');
alert('Your town is ' + result.data.towns + ' ' + result.data.state.replace( /\+/g , ' ' ));
}
Then the listener is applied to a field in the form here:
{
xtype: 'textfield',
name: 'city',
label: 'City*',
placeHolder: 'New York',
useClearIcon: true,
id:'city',
listeners: {
cityUpdate: function(city) {
console.log('event reponse' , this.fieldEl.dom , city);
}
}
},
Can someone explain to me why I am not able to see the event response call in the console? I see event added and event fired, but I never seem to get the event to actually run the event responded console statement. I receive no errors in the console, so I’m at somewhat of a loss as to what is happening here?
It looks like the form is firing the event, but you’ve added the listener to a textfield that is on the form.
If
usersFormis the one that callsfireEvent, then the listener for that event needs to be on usersForm itself.What happens if you add a
cityUpdatehandler to the first snippet of code, in the same block asbeforeactivateanddeactivate? Does that catch the event? If so, were you not expecting it to be caught there? Might be a slight design problem if so.