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

Commit dc1e55c

Browse files
pkozlowski-opensourceIgorMinar
authored andcommitted
fix(form): pick the right attribute name for ngForm
Closes #2997
1 parent 408e868 commit dc1e55c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/ng/directive/form.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function FormController(element, attrs) {
4040
errors = form.$error = {};
4141

4242
// init state
43-
form.$name = attrs.name;
43+
form.$name = attrs.name || attrs.ngForm;
4444
form.$dirty = false;
4545
form.$pristine = true;
4646
form.$valid = true;
@@ -102,7 +102,7 @@ function FormController(element, attrs) {
102102
*
103103
* @description
104104
* Sets the validity of a form control.
105-
*
105+
*
106106
* This method will also propagate to parent forms.
107107
*/
108108
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)