PDA

View Full Version : XTemplate - functions



archmisha
7 Aug 2009, 1:48 PM
Hi,
suppose i am having template that got:
"<span onclick='this.myfunc()'>click me</span>"

I want to be able to point from the template to one of my functions in the component to bind the onclick event.
Is it possible, or the funcitions must be a global one?

thanks

Animal
7 Aug 2009, 2:00 PM
Do not do it like that.

Add an onclick listener to the element which the Template writes into.

archmisha
7 Aug 2009, 11:14 PM
but then how i determine in the event function that the click was actuallu on the span and not on some other place of the enclosing component?

Maybe i should add id to the span and after calling overwrite method of the template use Ext.get() to get my span and add the listener?

And another question, where should i put the overwrite method call? Currently i made a delayed task in the onRender method that does the overwrite... is it ok?

Animal
7 Aug 2009, 11:30 PM
By giving the span a class and using the delegate option on the listener.

This has been covered here many times.

archmisha
7 Aug 2009, 11:38 PM
Thanks Animal, i will search the forums for the delegate option.
Currently i am trying to get into the onclick event of the panel that i write my template into.
I am not seeing in the documentation that there is onclick event for Panel.

Animal
7 Aug 2009, 11:41 PM
This is the 18783277th time someone has wanted a DOM event from a Component.

Add the listener to the element of the Panel that you want to add it to on render.

Maybe you want to add a listener to the body? or the header?