Skip to content

Commit 2f9fe72

Browse files
fix(form): pick the right attribute name for ngForm
1 parent 3e39ac7 commit 2f9fe72

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ng/directive/form.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -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;

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="ngForm"><input type="text" name="alias" ng-model="value"/></div>' +
70+
'</form>')(scope);
71+
72+
expect(scope.myForm).toBeDefined();
73+
expect(scope.myForm.ngForm).toBeDefined();
74+
expect(scope.myForm.ngForm.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)