Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
feat(forms): use the ng-form attribute as the name of the inner form
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko committed Mar 5, 2014
1 parent f918d4d commit 5b1416b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/directive/ng_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ part of angular.directive;
@NgDirective(
selector: '[ng-form]',
publishTypes : const <Type>[NgControl],
map: const { 'ng-form': '@name' },
visibility: NgDirective.CHILDREN_VISIBILITY)
class NgForm extends NgControl implements Map<String, NgControl> {
/**
Expand Down Expand Up @@ -50,8 +51,10 @@ class NgForm extends NgControl implements Map<String, NgControl> {
@NgAttr('name')
get name => _name;
set name(value) {
super.name = value;
_scope.context[name] = this;
if(value != null) {
super.name = value;
_scope.context[name] = this;
}
}

//FIXME: fix this reflection bug that shows up when Map is implemented
Expand Down
21 changes: 21 additions & 0 deletions test/directive/ng_form_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ void main() {
expect(form.invalid).toBe(false);
}));

it('should register the name of inner forms that contain the ng-form attribute',
inject((Scope scope, TestBed _) {

var element = $('<form name="myForm">'
' <div ng-form="myInnerForm" probe="f">' +
' <input type="text" ng-model="one" name="one" probe="m" />' +
' </div>' +
'</form>');

_.compile(element);
scope.apply(() {
scope.context['one'] = 'it works!';
});

var form = scope.context['myForm'];
var inner = _.rootScope.context['f'].directive(NgForm);

expect(inner.name).toEqual('myInnerForm');
expect(scope.eval('myForm["myInnerForm"]["one"].viewValue')).toEqual('it works!');
}));

it('should set the validity for the parent form when fieldsets are used', inject((Scope scope, TestBed _) {
var element = $('<form name="myForm">'
' <fieldset probe="f">' +
Expand Down

0 comments on commit 5b1416b

Please sign in to comment.