View Full Version : Referring to items in a view

4 Feb 2013, 11:37 AM
Is there a preferred way to refer to other items within a view?

In the code below, I'm trying to refer to the text area after the "Save" button is pressed in my onBtnAddNoteTap, so I can fire off an event with the value of the text area, rather than having a direct reference to the text area in my controller.

Ext.define('MyApp.view.AddNoteView', { extend: 'Ext.form.Panel',

config: {
items: [
xtype: 'textareafield',
id: 'txtAddNote',
itemId: 'txtAddNote',
padding: '0 0 20 0',
label: 'Note'
xtype: 'button',
itemId: 'btnAddNote',
text: 'Save'
listeners: [
fn: 'onBtnAddNoteTap',
event: 'tap',
delegate: '#btnAddNote'

onBtnAddNoteTap: function(button, e, options) {
console.log(this.txtAddNote,'button - getTxtAddNote');


4 Feb 2013, 1:02 PM
And to expand on this slightly...I added a keyup listener on my textfield to try setting the values and then getting the values right after, and nothing is set and getValues() returns an empty object. I'm just not sure what I'm doing wrong here.

onTxtAddNoteKeyup: function(textfield, e, options) { this.setValues({note:textfield.getValue()});

4 Feb 2013, 1:39 PM

5 Feb 2013, 6:07 AM
Excellent! Thanks.

Now does anyone know if there's a reason that this.getValues() is not working. "this" definitely seems to be referring to the "Ext.form.Panel". The method is there. Just keeps returning an empty object. I even set the values and then try to get the values right after, but still an empty object.

5 Feb 2013, 6:16 AM
You should post your code you're using to set the values. My guess is that since the items in your form panel don't have a "name" parameter, the setValues() call doesn't know what to do with the data you're passing in to it.

5 Feb 2013, 9:35 AM
That was exactly it. Thanks again. I skipped right over the "name" part in the documentation. I thought I would just be able to set a struct for the panel, then get that struct back out again. Guess I need to dive into the Sencha code a little more.