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

Commit

Permalink
fix(form): pick the right attribute name for ngForm
Browse files Browse the repository at this point in the history
Closes #2997
  • Loading branch information
pkozlowski-opensource authored and IgorMinar committed Jul 24, 2013
1 parent 408e868 commit dc1e55c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ng/directive/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions test/ng/directive/formSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dc1e55c

Please sign in to comment.