From 5b1416b4b9f447132aaa40ac393226841168fc32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Wed, 5 Mar 2014 16:09:19 -0500 Subject: [PATCH] feat(forms): use the ng-form attribute as the name of the inner form --- lib/directive/ng_form.dart | 7 +++++-- test/directive/ng_form_spec.dart | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/directive/ng_form.dart b/lib/directive/ng_form.dart index 453f5f056..3762aba8e 100644 --- a/lib/directive/ng_form.dart +++ b/lib/directive/ng_form.dart @@ -20,6 +20,7 @@ part of angular.directive; @NgDirective( selector: '[ng-form]', publishTypes : const [NgControl], + map: const { 'ng-form': '@name' }, visibility: NgDirective.CHILDREN_VISIBILITY) class NgForm extends NgControl implements Map { /** @@ -50,8 +51,10 @@ class NgForm extends NgControl implements Map { @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 diff --git a/test/directive/ng_form_spec.dart b/test/directive/ng_form_spec.dart index df8187c30..775e115ac 100644 --- a/test/directive/ng_form_spec.dart +++ b/test/directive/ng_form_spec.dart @@ -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 = $('
' + '
' + + ' ' + + '
' + + '
'); + + _.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 = $('
' '
' +