From dc1e55ce1a314b6c1ad4b9d5b4a31226e1fa1e18 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Thu, 18 Jul 2013 20:44:27 +0200 Subject: [PATCH] fix(form): pick the right attribute name for ngForm Closes #2997 --- src/ng/directive/form.js | 4 ++-- test/ng/directive/formSpec.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js index 77f4379e2032..72f752beca08 100644 --- a/src/ng/directive/form.js +++ b/src/ng/directive/form.js @@ -40,7 +40,7 @@ function FormController(element, attrs) { errors = form.$error = {}; // init state - form.$name = attrs.name; + form.$name = attrs.name || attrs.ngForm; form.$dirty = false; form.$pristine = true; form.$valid = true; @@ -102,7 +102,7 @@ function FormController(element, attrs) { * * @description * Sets the validity of a form control. - * + * * This method will also propagate to parent forms. */ form.$setValidity = function(validationToken, isValid, control) { diff --git a/test/ng/directive/formSpec.js b/test/ng/directive/formSpec.js index 347d44769f11..f8e4cf63be38 100644 --- a/test/ng/directive/formSpec.js +++ b/test/ng/directive/formSpec.js @@ -63,6 +63,17 @@ describe('form', function() { expect(scope.myForm.alias).toBeDefined(); }); + it('should use ngForm value as form name when nested inside form', function () { + doc = $compile( + '
' + + '
' + + '
')(scope); + + expect(scope.myForm).toBeDefined(); + expect(scope.myForm.nestedForm).toBeDefined(); + expect(scope.myForm.nestedForm.alias).toBeDefined(); + }); + it('should publish form to scope when name attr is defined', function() { doc = $compile('
')(scope);