PDA

View Full Version : Controller refs are "undefined"



catacaustic
23 Sep 2012, 3:16 PM
I'm trying to use refs in a controllers function and this is giving me an error when I'm trying to use the auto-generated getter functions for refs.

I'm calling this from a primary controller:

setUser: function (grid, td, cell, rec) {
this.getController ("Adminuser").setName (rec.get ("name"));
}, // setUser ()
This part works correctly, gets the name, and passes it off to the second controller.

Then inside my second controller I have:

refs: [
{
ref: "usersNameField",
selector: "adminuser tbtext[type=usersname]"
}
]

...

setName: function (name) {
console.log ("Controller setting name as '" + name + "'");
this.getUsersNameField ().setText (name);
}, // setName ()


The error that I get is:

TypeError: this.getUsersNameField() is undefined

I'm pretty sure that this is a scope issue, but I can't figure out where the error is coming from. Does anyone have an idea of where I'm going wrong?

vietits
23 Sep 2012, 10:53 PM
Ther error means that this.getUsersNameField() returns null. So you should check to make sure that component which matches "adminuser tbtext[type=usersname]" is on the document. You can also modify your code to check this.


setName: function (name) {
console.log ("Controller setting name as '" + name + "'");
// this.getUsersNameField ().setText (name);
var usersNameField = this.getUsersNameField();
if(usersNameField) usersNameField.setText(name);
}, // setName ()