aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Kozlowski2013-07-18 20:44:27 +0200
committerIgor Minar2013-07-24 14:22:05 -0700
commit0fcd1e3b1fa6244d02f08631d9ef81bf79996fab (patch)
tree4ac4fef63118be7a95958641871fb46a1fc3a814
parent47a2a9829f0a847bbee61cd142c43000d73ea98b (diff)
downloadangular.js-0fcd1e3b1fa6244d02f08631d9ef81bf79996fab.tar.bz2
fix(form): pick the right attribute name for ngForm
Closes #2997
-rw-r--r--src/ng/directive/form.js6
-rw-r--r--test/ng/directive/formSpec.js11
2 files changed, 14 insertions, 3 deletions
diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js
index 5eec23f1..a348babf 100644
--- a/src/ng/directive/form.js
+++ b/src/ng/directive/form.js
@@ -23,7 +23,7 @@ var nullFormCtrl = {
*
* - keys are validation tokens (error names) — such as `required`, `url` or `email`),
* - values are arrays of controls or forms that are invalid with given error.
- *
+ *
* @description
* `FormController` keeps track of all its controls and nested forms as well as state of them,
* such as being valid/invalid or dirty/pristine.
@@ -42,7 +42,7 @@ function FormController(element, attrs) {
controls = [];
// init state
- form.$name = attrs.name;
+ form.$name = attrs.name || attrs.ngForm;
form.$dirty = false;
form.$pristine = true;
form.$valid = true;
@@ -108,7 +108,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 f6173414..b3673264 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(
+ '<form name="myForm">' +
+ '<div ng-form="nestedForm"><input type="text" name="alias" ng-model="value"/></div>' +
+ '</form>')(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('<form name="myForm"></form>')(scope);