With a template in hand, I needed to toggle the display of certain text based on a method's return value. Research led me to the recommendation of using handlebars helpers for this purpose. So, I implemented a resetPassword
helper within the controller. While the options.fn(this)
part functions correctly, the options.inverse(this)
does not, resulting in the common JS error
Uncaught TypeError: undefined is not a function
....
templates/reset-password.hbs:
<div class = "container">
{{#resetPassword}}
<h4>Password has been reset</h4>
<h5>Your new password is: <b>{{password}}</b></h5>
{{else}}
<h4>Something went wrong! </h4>
<h5>The password has not been reset! Please try again later.</h5>
{{/resetPassword}}
</div>
controllers/reset-password.js:
export default Ember.Controller.extend({
token: null,
init: function ()
{
this._super();
Ember.Handlebars.registerHelper('resetPassword', function (options)
{
var token = this.get('token');
var result = false;
/* Ember.$.ajax({
type: "POST",
url: "/reset_password",
contentType: "text/html",
dataType: "json",
async: false,
beforeSend: function (request)
{
request.setRequestHeader("Authorization", token);
},
success: function (data, textStatus)
{
this.set('password', data.password);
result = true;
},
error: function (data, textStatus)
{
result = false;
}
});*/
if (result)
{
return options.fn(this);
}
return options.inverse(this);
});
}
});