Lizzy249
Lizzy249

Reputation: 41

Get input of textfield

I have an textfield in Sencha Touch 2 and a button. I would like to get the input of the textfield when button is pressed. I tried it with Ext.ComponentQuery, but it didn't work. Have someone an example how to do that?

{
    xtype: 'textfield',
    cls: 'inputfields',
    id: 'title',
},
{
    xtype: 'button',
    ui: 'action',
    name: 'textfieldButton',
    handler : function(){
        // what should go here ?
    }
}

Upvotes: 4

Views: 5625

Answers (2)

Urmil Setia
Urmil Setia

Reputation: 159

My way of doing it is Ext.getCmp('title').getValue();

Also please refer to the Docs (Docs API). They are really Helpful.

Upvotes: 4

plesiv
plesiv

Reputation: 7028

You could do:

var value = Ext.ComponentQuery.query('#title')[0].getValue();
// test by writing in console
console.log(value);

TIP 1: It's helpful to have API reference of Sencha open all the time when you use this framework (likewise for any other framework, programming language etc.). For speed, I suggest downloading it.
TIP 2: In Chrome Ctrl+Shift+I for developer tools; you can access console there.

Upvotes: 2

Related Questions