Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

support binding more "presence-only attributes" to an expression #694

Closed
lanterndev opened this issue Dec 19, 2011 · 7 comments
Closed

support binding more "presence-only attributes" to an expression #694

lanterndev opened this issue Dec 19, 2011 · 7 comments

Comments

@lanterndev
Copy link
Contributor

From e.g. the ng:checked docs:

The HTML specs do not require browsers to preserve the special attributes such as checked. (The presence of them means true and absence means false) This prevents the angular compiler from correctly retrieving the binding expression. To solve this problem, we introduce ng:checked.

The ng:disabled docs have something similar. But these aren't the only attributes whose mere presence (rather than value) determines behavior. The required attribute of input elements (introduced in html5) is one example, and I don't see a way to bind its presence to the result of an expression. I see there's ng:required, but it works differently, and begs the question (you'd have to bind its presence to an expression too). Is there currently some way to achieve this with the required attribute? With an arbitrary attribute?

P.S. Thanks for the awesome work. Angular is amazing.

@IgorMinar
Copy link
Contributor

Do I understand this correctly that you want to be able to bind to ng:required so that you can dynamically specify if a input field is required or not?

If so then this is being addressed in https://github.com/mhevery/angular.js/commits/directive.

@lanterndev
Copy link
Contributor Author

Oh, great news. I'll close this ticket then. Please let me know if there's another ticket I can follow to track progress on this. Thanks!

@IgorMinar
Copy link
Contributor

The change is part of a larger effort: https://github.com/angular/angular.js/issues?milestone=8

@lanterndev
Copy link
Contributor Author

Cool, I'll follow that milestone, thanks. Thought of another html5 "presence-only" attribute: autofocus. It would be sweet to have a way of binding arbitrary presence-online attributes to expressions.

@IgorMinar
Copy link
Contributor

the presence-only attributes are officially called boolean attributes and
there is quite a few of them: http://www.w3.org/TR/html5/Overview.html

with regards to autofocus, the html5 spec says that the focus should be
placed on the element when it is "inserted into the document" and there is
also an additional restriction that says that there can be no more than one
element with attribute autofocus in the document.

so autofocus is quite tricky and requires special treatment. can you please
create a new issue for this and reference this issue or just quote this
comment.

@lanterndev
Copy link
Contributor Author

Opened #698 to track autofocus, thanks.

So does it make any sense to have a generic way of binding boolean attributes to an expression, so you can add arbitrary boolean attributes conditionally, or is there some way to do that already?

@IgorMinar
Copy link
Contributor

thanks for creating the new issue.

the thing is that some of these boolean attributes require special treatment - autofocus being a good example. So it's not just about expanding some vocabulary by adding new names to it.

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