In another question someone explained how to create a generic search box for a Nested List.
How to add a Search Bar to a Nested List?
How can I add/set a keyup listener to this class at the time of creation? I could add the listener on the class but I want to reuse this class on several screens.
Ext.define('Sencha.view.SearchBar', { extend: 'Ext.Toolbar', xtype : 'searchbar', requires: ['Ext.field.Text', 'Ext.field.Search'], config: { ui: 'searchbar', layout: 'vbox', cls: 'big', items: [ { xtype: 'searchfield', placeHolder: 'Search...', listeners: { scope: this, keyup: function(field) { console.log(field.getValue()); } } } ] } });
Can I add the listener directly to the searchfield at this point?
var searchBar = nestedList.add({ docked: 'top', xtype: 'searchbar', height: 100 });
I also tried adding a listener like this but I think I need to be able to access the field directly
searchBar.on('keyup', function(field) { console.log("foo..."); console.log(field.getValue()); }, this);
====================================
[Update] Adding the delegation to the class:
Ext.define('Sencha.view.SearchBar', { extend: 'Ext.Toolbar', xtype : 'searchbar', requires: ['Ext.field.Text', 'Ext.field.Search'], config: { ui: 'searchbar', layout: 'vbox', cls: 'big', items: [ { xtype: 'searchfield', placeHolder: 'Search...' } ] }, initialize: function() { this.on({ scope: this, delegate: 'searchfield', keyup: 'onSearchFieldKeyUp' }); }, onSearchFieldKeyUp: function(field) { console.log("Base Class"); console.log(field.getValue()); } });
Next instantiate 'searchbar' with our own method to override default onSearchFieldKeyUp
var searchBar = this.nestedList.add({ docked: 'top', xtype: 'searchbar', height: 75, id: 'searchbarId' });