Multiple click events on same element

I need to activate multiple function (or rather, expression) when a click event occure.
I know I can move all of my logic into a wrapper function and call that from the delegate,
but in my case it would be very helpful if I could call multiple handlers from the view directly.

I’ve seen this question asked a lot of time in SO.
with no real good answers.

a colleague suggested I try the following: and to my surprise - it worked.

<button click.delegate="[click1(), click2()]">multiple click handlers</button>

but I couldn’t find any reference in the docs, or in any of the SO questions below.
so I wanted to know, if its “legit”.
when did it became available?

I think this syntax is weird. I would preferred <button click.delegate="click1(); click2();">multiple click handlers</button>

what is the direction of Aurelia2 in that context?

1 Like

As you noticed, [click1(), click2()] is a valid JS expression, while expression1;expression2 is not, because of the ;
So to answer your Q:

when did it became available?

It’s been always available, just that not popular and recommended. Though I do this

<button click.trigger="expression1() || expression2() || expression3()">

sometimes.

3 Likes