PDA

View Full Version : Access to textfield value in tbar



stv-linux
13 Aug 2010, 11:32 PM
Hi,
I have a textfield and a button in a tbar, when I write a text in textfiled and press the buttom start the load of a datastore for a grid.

Definition of the textfield


var searchField = {
xtype: 'textfield',
displayField: 'name',
valueField: 'name',
editable: true,
forceSelection: true,
triggerAction: 'all',
emptyText: 'Search...',
selectOnFocus: true,


Definition of the tbar:



searchField,
{xtype: 'tbbutton', text: 'Search', icon: 'images/bomb.png', handler: function(){
Store.load({params: { 'search': searchField.getvalue() }});
}},


All work correcrtly, I see the tbar, I see the test field and the button, alsto the ajax request work for load datastore but I not able to read the value of the text field by the function in button handler. (IN RED) then when I load the datastore the params SEARCH is always empity.

Thanks in advance

Steve

How I can do it ?

ashaihullin
13 Aug 2010, 11:41 PM
i think you need to use scope or get your field by ID

stv-linux
13 Aug 2010, 11:44 PM
Thanks for your reply,

use scope how ? can you post me an example ?

ashaihullin
14 Aug 2010, 12:09 AM
Something like this:


Ext.onReady(function(){

searchField = new Ext.form.TextField({
displayField: 'name',
valueField: 'name',
editable: true,
forceSelection: true,
triggerAction: 'all',
emptyText: 'Search...',
selectOnFocus: true
});

var but = new Ext.Button({
text: 'Search',
scope: this,
handler: function(){
console.log(this.searchField.getValue());
}
});

var pan = new Ext.Panel({
items: [but],
bbar: [ searchField ]

});

pan.render( document.body );
});


just play with it...

stv-linux
14 Aug 2010, 8:47 AM
WORK! Thanks a lot
Steve