angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

ng-enabled

Open cricardol opened this issue 14 years ago • 106 comments

Should this attribute be created in a future release?

cricardol avatar Aug 10 '12 14:08 cricardol

I think the whole precedence discussion about a possible but unlikely scenario of having the conflicting directives on the same element is a distraction.

The real question is do we want this in Angular core or not. Either way we go, we should have a reason for it and I'm sorry but many +1 are not enough force the decision. Consistency and predictability are more important.

ngDisabled and other directives that bind to boolean attributes exist only because in certain versions of IE we can't bind directly to disabled (or other boolean) attributes because IE will not store the value of the disabled attribute in the DOM. So if template contains <input disabled="{{someCondition}}">, the parsed DOM be the same as if the template was just <input disabled>. This is why ngDisabled exists - it allows the template to not be messed up in IE. If it weren't for IE, we wouldn't have ngDisabled.

So what's up with ngEnabled? Q: Would it be convenient to have it? A: Sometimes. Q: Would it be consistent with the rest of the system? A: No.

If we wanted to make it consistent with the rest of the system, we'd have to created ngReadWrite (as an opposite for ngReadOnly), ngUnselected (as an opposite for ngSelected), ngUnchecked (for ngChecked) and the list goes on and on and becomes more ridiculous the more exotic the boolean attributes get. As you can see this would cause an api explosion and would not add much value for anyone.

Q: What about ngShow/ngHide? A: they should not exist. We should just bind to the hidden attribute and if anything have the ngHidden directive for IE. That's the direction we'll go in Angular2. It's too late to change it in Angular1.

So what if someone wants ngEnabled really really badly? Just write a new module and share it via bower or npm. You can start off with this code: http://plnkr.co/edit/zzBMyd5REGcVEjUzkovQ?p=preview

Now why on earth was this labeled as "PRs plz" is not clear to me. I think it was done by an accident by someone on the team and I apologize for that.

I'm sorry to disappoint many people on this thread, but we need to keep Angular focused and consistent. If someone can be done via a non-core module then it should be done that way. Otherwise we'll end up with a bloated code base that contains random features that overall make no sense.

IgorMinar avatar Jul 17 '14 06:07 IgorMinar

I made a npm module/bower component here –> https://github.com/btford/angular-enabled

btford avatar Jul 17 '14 16:07 btford

@bford, you are the man!

@IgorMinar, thank you for your thoughtful reply and the additional context that went into your decision.

zdennis avatar Jul 17 '14 17:07 zdennis

+5

armw4 avatar Oct 30 '14 05:10 armw4

If we wanted to make it consistent with the rest of the system, we'd have to created ngReadWrite (as an opposite for ngReadOnly), ngUnselected (as an opposite for ngSelected), ngUnchecked (for ngChecked) and the list goes on and on and becomes more ridiculous the more exotic the boolean attributes get. As you can see this would cause an api explosion and would not add much value for anyone.

"We can't add X, even though dozens are asking for it, because we wouldn't want to add Y and Z, which no-one is asking for."

mdr avatar Nov 24 '14 15:11 mdr

From the perspective of interface design, logic should be named using positive terms. As @graphnode says above it is confusing that the value true disables something. True (positive) should be associated with something positive (enabled).

Some argue that ngDisabled is named such since it controls the disabled HTML attribute and therefore an ngEnabled makes no sense ... since there is no enabled HTML attribute. And that's a fair point. The question becomes: is ngDisabled a low level helper for the disabled attribute? Or is it a higher level feature -- the way to control whether something is enabled?

I suggest that it should be the latter. First, adding abstraction to a system leads to better code. Second, as a programmer with limited HTML experience I would rather rely on a library such as NG than to learn about the details of HTML. I'd be happy if I never knew that HTML had a disabled attribute.

FWIW I do not think that ngEnabled should be added for completeness -- since both ngHide and ngShow exist. Therefore, there is no need for something like ngUnchecked. Besides, that's negative. ngChecked is the right choice.

stevebroshar avatar Feb 19 '15 17:02 stevebroshar

:+1: what @stevebroshar says! Abstract away from freaky lower level details.

kdekooter avatar Feb 19 '15 18:02 kdekooter

Symfony2 has a project tag DX, which stands for Developer Experience.

The option to support ng-support would really qualify to improve the angularjs developer experience.

martijn80 avatar Mar 25 '15 14:03 martijn80

I have to agree with @IgorMinar and @stevebroshar. I understand why Igor doesn't want to add it and his arguments are very valid, however I think steve broshar's counter is the correct way to go. Unless it's impossible to implement it this way and support IE. Negative logic statements are just bad, even if HTML surfaces it that way.

blakekl avatar Mar 31 '15 15:03 blakekl

@blakekl: I don't view it as negative logic or positive logic, but rather a way to deviate from the default. By default, form fields are enabled (interactive, usable, clickable, etc), and write-able; check boxes by default are un-checked; dropdown options are by default unselected (and default to the top row by UI convention).

The HTML boolean attributes only serve to override the default behavior, and do not take any stance on positivity or negativity. There's nothing negative or positive about a read-only field, it's just read-only.

You may decide that "enabled" is positive and "disabled" is negative, but that's only true in the context of your particular application.

jamesdaily avatar Mar 31 '15 21:03 jamesdaily

@jamesdaily +1 perfect!

It is funny to see how much philosophy is hidden behind an ng-enabled attribute. It is also funny to see how customers (developers using angular for real applications) requesting an enhancement are dismissed basing the reasoning on not sustainable arguments. If the attribute would be useful: it, guess what, will be useful. And that regardless of any html related negative logic you may put behind that.

So for the sake of maintaining this comment page under 1GB in space you shall really listen to the requests and insert the new attribute. Or at least remove the ng-show one, as at that point would be unnecessary if not confusing.

ivan-saorin avatar Apr 01 '15 08:04 ivan-saorin

this is a perfect example of how developers can become arrogant stubborns.

mstdokumaci avatar Apr 01 '15 08:04 mstdokumaci

@mstdokumaci : Code of conduct I just hope you understand that this way of communicating is deemed unacceptable here?

SanderElias avatar Apr 01 '15 10:04 SanderElias

@jamesdaily I use the terms 'positive' and 'negative' loosely, mostly based on my experience that using what I called 'negative' frequently results in code that reads with double negatives. Positive is simply the opposite. Sorry if the terminology was confusing. I didn't mean it to be.

I frequently see form submit buttons with something like: ng-disabled="!isValid();" which seems to cause confusion on our team.

blakekl avatar Apr 01 '15 14:04 blakekl

@blakekl, I see your point, but then again you can simply do: ng-disabled="isInvalid()" right? And if you really want, it's easy enough to write your own xxDisabled directive That's just a single way to resolve the issue!

SanderElias avatar Apr 01 '15 14:04 SanderElias

+1 on having it baked in

wspringer avatar Apr 22 '15 07:04 wspringer

please put in ng-enabled

nithinankam avatar May 26 '15 21:05 nithinankam

+1024

ilaipi avatar Jun 29 '15 08:06 ilaipi

My dear ng-enabled , I miss you so much ...

sap9433 avatar Jul 29 '15 04:07 sap9433

An argument that ng-enabled should not exist because there's no such attribute as "enabled" is irrelevant when compared to the fact that there's no attribute show or hide, but even though we do have two counterparts in angular. If we spoke about ng-attr-enabled - then I would agree. But to me ng-enabled would be just a helper, just like ng-disabled and - as many have stated before - stand for readability which I bet all developers of angularjs fight and advocate for.

moniuch avatar Aug 06 '15 09:08 moniuch