Skip to content
This repository has been archived by the owner on Mar 22, 2019. It is now read-only.

Very confusing sentences around preventDefault #3850

Closed
sonic1981 opened this issue Mar 6, 2019 · 1 comment
Closed

Very confusing sentences around preventDefault #3850

sonic1981 opened this issue Mar 6, 2019 · 1 comment

Comments

@sonic1981
Copy link

Current Behavior

On the page https://guides.emberjs.com/v3.8.0/templates/actions/ there is the following text:

By default, the {{action}} helper prevents the default browser action of the DOM event. If you want to allow the browser action, you can stop Ember from preventing it.

For example, if you have a normal link tag and want the link to bring the user to another page in addition to triggering an ember action when clicked, you can use preventDefault=false:

<a href="newPage.htm" {{action "logClick" preventDefault=false}}>Go</a>

With preventDefault=false omitted, if the user clicked on the link, Ember.js will trigger the action, but the user will remain on the current page.

With preventDefault=false present, if the user clicked on the link, Ember.js will trigger the action and the user will be directed to the new page.

This is extremely confusing. I actually had to knockup a test program to understand what it was trying to say. TBF, this functionality is very confusing also but lets park that

Possible Solution

Illustrate this using examples:

By default, the {{action}} helper prevents the default browser action of the DOM event. So the following standard link:

<a href="newPage.htm" {{action "logClick"}}>Go</a>

Clicking on this link does not go to newPage.htm because the action has overridden this functionality. This is the default behaviour for Ember.

You can override this behaviour and make this work more like a standard non-ember anchor tag by using the preventDefault=false overload of the action on a a tag. For example:

<a href="newPage.htm" {{action "logClick" preventDefault=false}}>Go</a>

This still triggers the logClick action but then we also go to newPage.htm. .

You can specify preventDefault=true and this reverts to the standard Ember functionality (see previous example).

@locks
Copy link
Contributor

locks commented Mar 9, 2019

Tracking issue in PR, since it is not possible to transfer issues across organizations. Thanks for the help!

@locks locks closed this as completed Mar 9, 2019
jenweber pushed a commit to ember-learn/guides-source that referenced this issue Mar 16, 2019
This is in relation to issue emberjs/website#3850
previously merged using pull request #569
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants