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

feat(ngName): allow interpolated name for form controls #2988

Closed
wants to merge 1 commit into from

Conversation

Pasvaz
Copy link

@Pasvaz Pasvaz commented Jun 17, 2013

ngName allows forms' fields to set their name dynamically, especially useful with ngRepeat.
Right now is not possible to validate form controls like this: <input type="text" name="{{field.name}}" ng-model="field.data">
The current work-around is to use one nested form for each field but indeed it's an hack rather than a solution.

This implementation could be moved inside the directive ngModel or within its own directive ngName, I left intentionally it in the NgModelController because it's slightly faster, however I can refactor it as you prefer.

this fixes also the issues #1404 and #2426

ngName allows forms' fields to set their name dynamically, especially useful with ngRepeat.
Right now is not possible to validate form controls like this: <input type="text" name="{{field.name}}" ng-model="field.data">
The current work-around is to use one nested form for each field but indeed it's an hack rather than a solution.

This implementation could be moved inside the directive 'ngModel' or within its own directive 'ngName', I left intentionally it in the NgModelController because it's slightly faster, however I can refactor it as you prefer.

this fixes also the issues angular#1404 and angular#2426
@Pasvaz
Copy link
Author

Pasvaz commented Jun 17, 2013

for instance

<input type="text" name="{{field.name}}" ng-model="field.data">

with this patch would be:

<input type="text" ng-name="field.name" ng-model="field.data">

@neoasterix
Copy link

+1

@lastnico
Copy link

Hi,

I think ngForm should also benefit from this improvement, as currently, the ng-form="static-name" and name="static-name" are not interpolated, meaning you cannot define a dynamic name for inner ng-form (again, this is especially needed for ng-form in ng-repeat loops), and, in the end, they won't be populating the parent form exported list of controls.

@damrbaby
Copy link
Contributor

damrbaby commented Jul 9, 2013

@lastnico see #3115, I wonder if that would take care of your use case

@gregbiv
Copy link

gregbiv commented Jul 11, 2013

👍

@petebacondarwin
Copy link
Contributor

PR Checklist (Minor Feature)

  • Contributor signed CLA now or in the past (if you just signed, leave a comment here with your real name for cross reference)
  • Feature improves existing core functionality
  • API is compatible with existing Angular apis and relevant standards (if applicable)
  • PR doesn't contain a breaking change
  • PR contains unit tests
  • PR contains e2e tests (if suitable)
  • PR contains documentation update
  • PR passes all tests on Travis (sanity)
  • PR passes all tests on ci.angularjs.org (cross-browser compatibility)
  • PR is rebased against recent master
  • PR is squashed into one commit per logical change
  • PR's commit messages are descriptive and allows us to autogenerate release notes (required commit message format)
  • All changes requested in review have been implemented

@petebacondarwin
Copy link
Contributor

@Pasvaz - can you make sure you sign the CLA? Thanks

@pkozlowski-opensource
Copy link
Member

@petebacondarwin I think we should focus on #3135 while considering this PR. The #3135 has associated unit tests and is not observing the name attribute.

@petebacondarwin
Copy link
Contributor

I agree. Should we close this one?

@pkozlowski-opensource
Copy link
Member

Yes imo. Working on 2 very similar prs doesn't make much sense and we shoul promote ones with unit tests.

@petebacondarwin
Copy link
Contributor

@Pasvaz - I think we will close this for now. Thank you for putting this PR together. Perhaps you could help us review and move the other PR forward? Thanks.

@Pasvaz
Copy link
Author

Pasvaz commented Jul 18, 2013

@petebacondarwin yes I signed the CLA about a month ago.

What about moving this code into its own directive ngName? I left it inside the ngForm for two reasons, it's faster and it takes care only of the ngName when it is inside a form, however I didn't like this approach, I would rather move it inside its own directive and provide also the feature to change the name of an element regardless if it is inside a form, having a directive ngName would allow me to make tests, docs and everything else.
Let me know what do you think about 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

Successfully merging this pull request may close these issues.

7 participants