I've created a Toggle Button in the postcreate function
this.signin = new ToggleButton({
showlabel: true,
checked: false,
label: this.nls.signin,
onChange: this._onBtnSignInChanged
}, this.btnSignIn);
In the onChange event, I'd like to change the label to another string.
_onBtnSignInChanged: function (val) {
if (val) {
this.set('label', nls.signin);
} else {
this.set('label', nls.signout);
}
}
However, this gives the error "Uncaught TypeError: Cannot read property 'signout' of undefined". What's the right way of accessing the nls to get that string? I suspect I have to use lang.hitch somewhere, but everywhere I've tried gives me another undefined error.
Solved! Go to Solution.
Ken,
If this.nls.signin (like Sapna recommends) in your function does not do the trick, then your lang.hitch would be here:
this.signin = new ToggleButton({
showlabel: true,
checked: false,
label: this.nls.signin,
onChange: lang.hitch(this, this._onBtnSignInChanged)
}, this.btnSignIn);
It looks like you are not referencing "this" in onChange event. shouldnt that be this.nls.signin and this.nls.signout. assuming that signout is defined in string.js?
Ken,
If this.nls.signin (like Sapna recommends) in your function does not do the trick, then your lang.hitch would be here:
this.signin = new ToggleButton({
showlabel: true,
checked: false,
label: this.nls.signin,
onChange: lang.hitch(this, this._onBtnSignInChanged)
}, this.btnSignIn);
In my original code, I had this.nls.signin but had stripped out the "this" at one point as I tried various options. This is what finally worked (although I could have sworn I tried this yesterday)
this.signin = new ToggleButton({
showlabel: true,
checked: false,
label: this.nls.signin,
onChange: lang.hitch(this, this._onBtnSignInChanged)
}, this.btnSignIn);
_onBtnSignInChanged: function (val) {
console.log(this.nls.signout);
if (val) {
this.signin.set('label', this.nls.signin);
} else {
this.signin.set('label', this.nls.signout);
}
}