Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't trigger action if its element is disabled #2240

Closed
wants to merge 2 commits into from

Conversation

rlivsey
Copy link
Contributor

@rlivsey rlivsey commented Mar 7, 2013

Fixes #1936

@jamesarosen
Copy link

+1

@rlivsey
Copy link
Contributor Author

rlivsey commented Mar 7, 2013

Should it still prevent-default if the element is disabled?

Thinking of links with href, if it's disabled then you'd click it and end up navigating to another page which probably isn't what should happen. Then again, technically disabled isn't valid on <a> IIRC.

@jamesarosen
Copy link

At first, I thought it should return false.

Then I reconsidered. You could conceivably have a jQuery plugin that shows a "why is this button disabled?" tooltip if you ever try to click something that's disabled. (Or, if you think that's silly, a click tracker on a feature that's not yet built that you use to figure out whether people are interested in the feature.)

Then I reconsidered again: there's already the bubbles property. How about obeying that?

@rlivsey
Copy link
Contributor Author

rlivsey commented Mar 7, 2013

@jamesarosen if event.preventDefault() is called it will still propagate so you could still have other listeners for those use-cases. If bubbles is false then you'd lose that - but you've got to have explicitly set that so if you want disabled links to propagate but non-disabled not to I think it's probably fine to require some custom coding.

I'm coming round to thinking that the disabled check should move down a few lines under the bubble check but will wait to see what others think before updating the pull request.

@wagenet
Copy link
Member

wagenet commented Mar 20, 2013

I'm not sure that I really like the action helper checking for attributes. At the same time I understand the usefulness of this change. I'd like to hear a bit more discussion on this.

@jamesarosen
Copy link

@wagenet AFAICT, the only alternative would be to use a custom view class that includes TargetActionSupport and check the attribute there.

Is it possible that the action helper is doing too much? Is there something it could delegate to?

I guess the other option is to say that the disabled flag's state had to come from somewhere. That's likely the controller, so the it can use that information in the action callback to cancel the event.

@SirZach
Copy link

SirZach commented Mar 20, 2013

@jamesarosen We've implemented that exact solution of a small view mixing in the TargetActionSupport and on the click function...

click: function () {
    if (!this.get('disabled') && !Em.isEmpty(this.get('action'))) {
      this.triggerActionWithContext();
    }
  }

(We extened TargetActionSupport to include context)

@lukemelia
Copy link
Member

I don't think {{action ...}} should look at the attributes of the element it is on. If support for disabled at this level is important (and I'm not yet convinced it isn't better handled elsewhere as others have mentioned), I think it would be better to see it as an option on the {{action ...}} helper.

@lukemelia lukemelia closed this May 21, 2013
@jamesarosen
Copy link

This leaves Ember without a default way of building a button that can be disabled. Yes, you can always build a view with TargetActionSupport, but that's what Em.Button was and that got removed, which indicates that it's not recommended.

@lukemelia
Copy link
Member

@jamesarosen what do you think about the approach of adding an option to the action helper?

@jamesarosen
Copy link

Totally decent :)

@lukemelia
Copy link
Member

Maybe you or @rlivsey want to implement?

@krisselden
Copy link
Contributor

@jamesarosen If you use a <button> for your action instead of an <a>, the disabled attribute will already suppress the click event and thus suppress the action. Does that not meet the goal of "a default way of building a button that can be disabled"?

@jamesarosen
Copy link

@kselden that might just be crazy enough to work.

@th0r
Copy link

th0r commented Jan 16, 2014

As I understand this PR hasn't been merged yet?

@rstudner
Copy link

<button type="button" class="btn btn-primary test_id_button_save_metric_time_series_widget"
          {{action 'saveWidget'}} {{bind-attr disabled='isWidgetHasTitle'}}>Save changes</button>

if isWidgetHasTitle returns either true, or false, the disabled attribute is never even set, or respected, on my button.

view code:
isWidgetHasTitle: function() {
var w = this.get('widget');
var c = w.get('config');
var t = c.title;
var l = t.length;
var result = l == 0;
if (result) {
return "true"
}

    return "false";
}.observes('widget.config.title')

I've tried returning true and "true", false and "false" just in case.

Neither provides even setting the disabled property, much less anything else in this thread.

thoughts?

@wagenet
Copy link
Member

wagenet commented Feb 25, 2014

@rstudner This should work and seems like a separate issue. Please create a JSFiddle and ask if someone on IRC in #emberjs can review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: disable binding for {{action}}
8 participants