Picture of Saral Sharma
onClick event in hbs file
by Saral Sharma - Wednesday, 6 November 2019, 2:03 PM
 

Can we use onClick event to call a function defined either in model or view? Something like showHideText() function in below code. If yes then is it correctly called in below code(in .hbs file)?

Code in HBS file:

<
img onclick="showHideText()" src="{{_graphic.src}}" data-large="{{_graphic.large}}" data-small="{{_graphic.small}}" {{#if _graphic.alt}}aria-label="{{_graphic.alt}}"{{else}}aria-hidden="true"{{/if}} />
Function defined in Model or View JS file of the component

showHideText
: function(){
console.log("The function is called when user clicked on the image.");
}
Picture of Matt Leathes
Re: onClick event in hbs file
by Matt Leathes - Wednesday, 6 November 2019, 4:39 PM
 
 Can we use onClick event to call a function defined either in model or view?
Yes, certainly. But not by adding it that way. You should do it using the 'events hash' of the view, for more info see the documentation for Backbone.View.
Picture of Saral Sharma
Re: onClick event in hbs file
by Saral Sharma - Thursday, 7 November 2019, 11:20 AM
 

Thanks Matt for your quick response. You are genius.

Cheers.