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

feat(form.FormController): add $getControls() #16601

Merged
merged 3 commits into from Jun 18, 2018

Conversation

Narretz
Copy link
Contributor

@Narretz Narretz commented Jun 15, 2018

Fixes #14749
Closes #14517
Closes #13202

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
feat

What is the current behavior? (You can also link to an open issue here)
there's no straight forward way to get all controls of a form

What is the new behavior (if this is a feature change)?
you can get a shallow copy of the form controls

Does this PR introduce a breaking change?
No

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Fix/Feature: Docs have been added/updated
  • Fix/Feature: Tests have been added; existing tests pass

Other information:
I decided against a synchronized copy (#14749 (comment)) because I don't see the clear benefit over a simple shallow copy + is slightly more involved to implmenent.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM. Just a couple of minor suggestions.

@@ -4,6 +4,7 @@
*/
var nullFormCtrl = {
$addControl: noop,
$getControls: noop,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should return an empty array (to respect the "contract" that $getControls() returns an array).
Maybe change it to valueFn([]).

* @description
* This method returns a **shallow copy** of the controls that are currently part of this form
* ({@link form.FormController `FormController`} /
* {@link ngModel.NgModelController `NgModelController`}) . This can be used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume here you refer to the fact that the controls can be either FormController or NgModelController instances. Having this parenthesis after "of this form" is a little confusing.

I think it makes sense to be more explicit about this in the docs (because not all people might realize controls can actually be other FormControllers) and also mention that if you want nested controls, you have to recursively call $getControls() on sub-forms.

@Narretz
Copy link
Contributor Author

Narretz commented Jun 18, 2018

@gkalpak Pr has been updated, PTAL


scope.$digest();

var form = doc,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable.

@Narretz Narretz merged commit 5b11145 into angular:master Jun 18, 2018
@Narretz Narretz deleted the feat-form-controls branch June 18, 2018 14:02
Narretz added a commit that referenced this pull request Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.