Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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