Skip to content
This repository has been archived by the owner on May 5, 2018. It is now read-only.

Add a ui-for directive for associating form labels with inputs #59

Closed
ProLoser opened this issue Jul 15, 2012 · 7 comments
Closed

Add a ui-for directive for associating form labels with inputs #59

ProLoser opened this issue Jul 15, 2012 · 7 comments
Assignees
Labels

Comments

@ProLoser
Copy link
Member

I don't want to have to ID every single <input> I use just so that my <label> can be properly attached. The need for an ID is also further rendered useless with the use of ng-model (which is essentially an identifier for the input). The idea would be that you could simply do and the label would automatically be attached to the (nearest/first?) input that uses that model.

Issues:

  • What if there are multiple inputs with the same ng-model? (probably should just use the first match or nearest match)
  • Is it acceptable to search the nearby DOM from within a directive (this is not normally done)
  • What if multiple inputs on the page use the same model, but represent different references (such as within ng-repeat)

Features:

  • Leverage existing IDs on the input if one is already present
@ghost ghost assigned ProLoser Jul 15, 2012
@dandoyon
Copy link
Contributor

I've felt the same way when coding up forms. Here's an idea:

  • Have the label's text as attribute ui-label="First Name" and prepend the element with a label (using transclusion). If there is an id use that, if not generate one. I believe angular has a built in nextnum thingy that could be useful. In future version, this could be useful for I18N. The directive could consult with a locale based dict to pull out translation using the locale & label as a hash.

@ProLoser
Copy link
Member Author

This could work, however I think Pete suggested almost the same exact thing on the google group and the thing is for me personally, I don't put the label right before (or next to) the original input all the time. If I could put a label right before the input, I feel like I might as well wrap the input in the label altogether and not worry about the for-attribute (if my CSS can handle it).

For this reason I'm still interested in finding an alternate solution. However this does not mean we can't also implement the solution you suggest, I'm just holding out for a more versatile solution.

@dandoyon
Copy link
Contributor

Probably will need to happen in stages.

@pkozlowski-opensource
Copy link
Member

@ProLoser @dandoyon I think that we could close this issue and focus on the ui-input from the #191. Thoughts?

@dandoyon
Copy link
Contributor

Agreed

Sent from my iPhone

On Sep 23, 2012, at 1:36 AM, Pawel Kozlowski [email protected] wrote:

@ProLoser @dandoyon I think that we could close this issue and focus on the ui-input from the #191. Thoughts?


Reply to this email directly or view it on GitHub.

@ProLoser
Copy link
Member Author

Alright, just realize that I would like to continue to break ui-input into sub-directives whenever possible.

@pkozlowski-opensource
Copy link
Member

Sure, I'm also not fan of big fat directives. I've got couple of ideas
on how to refactor things, will push changes as soon as I've got a bit
of time to finish my work on the ui-input. For now closing this issue
in favor of focusing efforts on the ui-input.

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

No branches or pull requests

3 participants