Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Cannot have multiple action helpers in the templates #569

Closed
pjg opened this Issue · 14 comments

5 participants

@pjg
pjg commented

With this code:

<li {{action "one" on="mouseEnter"}} {{action "two" on="click"}}>item</li>

Only the first action will be "registered" and later on fired (for mouseEnter). The second (for click) will be ignored.

Here is JSFiddle for that: http://jsfiddle.net/xJRrK/1/

I'm reporting because I think it would be really nice to have this and some folks at #emberjs recommended that as well.

CC @ebryn

@ebryn ebryn was assigned
@ebryn
Owner

I'm open to debating it, but I don't think we want to support this. The right thing to do is use a view.

@pjg
pjg commented

Hmm. My use case was that when you define {{action ".." on="mouseEnter"}} you almost always want to also define {{action ".." on="mouseLeave"}} as well. Currently this is not possible (without using view as you suggest).

@pangratz

I just thought about a different syntax with less DRY: <li {{action onMouseEnter="one" onClick="two"}}>item<li>

What do you think?

@pjg
pjg commented

+1 for @pangratz's suggestion. Much more concise.

@ebryn
Owner

:-1: You should use views for this type of interaction.

@pixelcort

The workaround I use to achieve this is to make nested elements each with different action handlers:

<div class="outer" {{action "doOneThing"}}><div class="inner" {{action "doAnotherThing"}}>Click Me</div></div>

I avoid making custom views as much as possible and prefer to throw this all in the templates.

@ebryn
Owner

@pixelcort Avoiding custom views seems bad. Is there a particular reason you are?

@pixelcort

@ebryn I enjoy having one place to find all my logic, which is in my templates using #with, #if and #action. The only place I use views is within ViewState instances and unfortunately with sublassing Em.TextField and friends to add more features.

That being said I'm fine continuing to use my nested element workaround for this specific case.

@wagenet
Owner

@pixelcort This seems like a misuse of Ember. Templates are not intended to hold much logic, this is the job of Views. Having to add extra markup to your templates for a workaround like this sounds like a bad idea.

@pjg

Hmm, so the question is why provide (limited) support for {{action}} tags in templates at all?

@wagenet
Owner

@pjg The point was to provide support for very simple cases, i.e. single action ones that didn't need any other special handling. A good use is for simple buttons and links that can just use CSS for hover states and the like.

@pjg

IMO it would be better to either fully support multiple {{action}} helpers in the templates or just deprecate/remove the feature altogether if this is a "wrong" approach to do things.

@wagenet
Owner

@pjg I definitely do sympathize with your position on this. I think this is something we'll discuss further. However, custom views are a very powerful part of Ember and should definitely be utilized when templates are becoming too complex.

@ebryn
Owner

It was decided previously that we're not going to support the use of multiple action helpers. Please use views if you need to handle multiple events.

@ebryn ebryn closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.