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

Commit 0fcd1e3

Browse files
pkozlowski-opensourceIgorMinar
authored andcommitted
fix(form): pick the right attribute name for ngForm
Closes #2997
1 parent 47a2a98 commit 0fcd1e3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/ng/directive/form.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var nullFormCtrl = {
2323
*
2424
* - keys are validation tokens (error names) — such as `required`, `url` or `email`),
2525
* - values are arrays of controls or forms that are invalid with given error.
26-
*
26+
*
2727
* @description
2828
* `FormController` keeps track of all its controls and nested forms as well as state of them,
2929
* such as being valid/invalid or dirty/pristine.
@@ -42,7 +42,7 @@ function FormController(element, attrs) {
4242
controls = [];
4343

4444
// init state
45-
form.$name = attrs.name;
45+
form.$name = attrs.name || attrs.ngForm;
4646
form.$dirty = false;
4747
form.$pristine = true;
4848
form.$valid = true;
@@ -108,7 +108,7 @@ function FormController(element, attrs) {
108108
*
109109
* @description
110110
* Sets the validity of a form control.
111-
*
111+
*
112112
* This method will also propagate to parent forms.
113113
*/
114114
form.$setValidity = function(validationToken, isValid, control) {

test/ng/directive/formSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ describe('form', function() {
6363
expect(scope.myForm.alias).toBeDefined();
6464
});
6565

66+
it('should use ngForm value as form name when nested inside form', function () {
67+
doc = $compile(
68+
'<form name="myForm">' +
69+
'<div ng-form="nestedForm"><input type="text" name="alias" ng-model="value"/></div>' +
70+
'</form>')(scope);
71+
72+
expect(scope.myForm).toBeDefined();
73+
expect(scope.myForm.nestedForm).toBeDefined();
74+
expect(scope.myForm.nestedForm.alias).toBeDefined();
75+
});
76+
6677

6778
it('should publish form to scope when name attr is defined', function() {
6879
doc = $compile('<form name="myForm"></form>')(scope);

0 commit comments

Comments
 (0)