OLD | NEW |
1 part of angular.directive; | 1 part of angular.directive; |
2 | 2 |
3 /** | 3 /** |
4 * The form directive listens on submission requests and, depending, | 4 * The form directive listens on submission requests and, depending, |
5 * on if an action is set, the form will automatically either allow | 5 * on if an action is set, the form will automatically either allow |
6 * or prevent the default browser submission from occurring. | 6 * or prevent the default browser submission from occurring. |
7 */ | 7 */ |
8 @NgDirective( | 8 @Decorator( |
9 selector: 'form', | 9 selector: 'form', |
10 publishTypes : const <Type>[NgControl], | 10 module: NgForm.module) |
11 visibility: NgDirective.CHILDREN_VISIBILITY) | 11 @Decorator( |
12 @NgDirective( | |
13 selector: 'fieldset', | 12 selector: 'fieldset', |
14 publishTypes : const <Type>[NgControl], | 13 module: NgForm.module) |
15 visibility: NgDirective.CHILDREN_VISIBILITY) | 14 @Decorator( |
16 @NgDirective( | |
17 selector: '.ng-form', | 15 selector: '.ng-form', |
18 publishTypes : const <Type>[NgControl], | 16 module: NgForm.module) |
19 visibility: NgDirective.CHILDREN_VISIBILITY) | 17 @Decorator( |
20 @NgDirective( | |
21 selector: '[ng-form]', | 18 selector: '[ng-form]', |
22 publishTypes : const <Type>[NgControl], | 19 module: NgForm.module, |
23 visibility: NgDirective.CHILDREN_VISIBILITY) | 20 map: const { 'ng-form': '@name' }) |
24 class NgForm extends NgControl implements Map<String, NgControl> { | 21 class NgForm extends NgControl { |
| 22 static final Module _module = new Module() |
| 23 ..factory(NgControl, (i) => i.get(NgForm)); |
| 24 static module() => _module; |
| 25 |
| 26 final Scope _scope; |
| 27 |
25 /** | 28 /** |
26 * Instantiates a new instance of NgForm. Upon creation, the instance of the | 29 * Instantiates a new instance of NgForm. Upon creation, the instance of the |
27 * class will be bound to the formName property on the scope (where formName | 30 * class will be bound to the formName property on the scope (where formName |
28 * refers to the name value acquired from the name attribute present on the | 31 * refers to the name value acquired from the name attribute present on the |
29 * form DOM element). | 32 * form DOM element). |
30 * | 33 * |
31 * * [scope] - The scope to bind the form instance to. | 34 * * [scope] - The scope to bind the form instance to. |
32 * * [element] - The form DOM element. | 35 * * [element] - The form DOM element. |
33 * * [injector] - An instance of Injector. | 36 * * [injector] - An instance of Injector. |
34 */ | 37 */ |
35 NgForm(Scope scope, dom.Element element, Injector injector) : | 38 NgForm(this._scope, NgElement element, Injector injector, Animate animate) : |
36 super(scope, element, injector) { | 39 super(element, injector, animate) { |
37 | 40 |
38 if (!element.attributes.containsKey('action')) { | 41 if (!element.node.attributes.containsKey('action')) { |
39 element.onSubmit.listen((event) { | 42 element.node.onSubmit.listen((event) { |
40 event.preventDefault(); | 43 event.preventDefault(); |
41 _scope.broadcast('submitNgControl', valid == null ? false : valid); | 44 onSubmit(valid == true); |
42 reset(); | 45 if (valid == true) { |
| 46 reset(); |
| 47 } |
43 }); | 48 }); |
44 } | 49 } |
45 } | 50 } |
46 | 51 |
| 52 /** |
| 53 * The name of the control. This is usually fetched via the name attribute th
at is |
| 54 * present on the element that the control is bound to. |
| 55 */ |
47 @NgAttr('name') | 56 @NgAttr('name') |
48 get name => _name; | 57 get name => _name; |
49 set name(value) { | 58 set name(String value) { |
50 super.name = value; | 59 if (value != null) { |
51 _scope.context[name] = this; | 60 super.name = value; |
52 } | 61 _scope.context[name] = this; |
53 | |
54 //FIXME: fix this reflection bug that shows up when Map is implemented | |
55 operator []=(String key, value) { | |
56 if (key == 'name') { | |
57 name = value; | |
58 } else { | |
59 _controlByName[key] = value; | |
60 } | 62 } |
61 } | 63 } |
62 | 64 |
63 //FIXME: fix this reflection bug that shows up when Map is implemented | 65 /** |
64 operator[](name) { | 66 * The list of associated child controls. |
65 if (name == 'valid') { | 67 */ |
66 return valid; | 68 get controls => _controlByName; |
67 } else if (name == 'invalid') { | |
68 return invalid; | |
69 } else { | |
70 return _controlByName[name]; | |
71 } | |
72 } | |
73 | 69 |
74 bool get isEmpty => false; | 70 /** |
75 bool get isNotEmpty => !isEmpty; | 71 * Returns the child control that is associated with the given name. If multi
ple |
76 get values => null; | 72 * child controls contain the same name then the first instance will be retur
ned. |
77 get keys => null; | 73 */ |
78 get length => null; | 74 NgControl operator[](String name) => |
79 clear() => null; | 75 controls.containsKey(name) ? controls[name][0] : null; |
80 remove(_) => null; | |
81 containsKey(_) => false; | |
82 containsValue(_) => false; | |
83 addAll(_) => null; | |
84 forEach(_) => null; | |
85 putIfAbsent(_, __) => null; | |
86 } | 76 } |
87 | 77 |
88 class NgNullForm extends NgNullControl implements NgForm { | 78 class NgNullForm extends NgNullControl implements NgForm { |
| 79 var _scope; |
| 80 |
89 NgNullForm() {} | 81 NgNullForm() {} |
| 82 operator []=(String key, value) {} |
| 83 operator[](name) {} |
90 | 84 |
91 operator[](name) {} | 85 get controls => null; |
92 operator []=(String name, value) {} | |
93 | |
94 bool get isEmpty => false; | |
95 bool get isNotEmpty => true; | |
96 get values => null; | |
97 get keys => null; | |
98 get length => null; | |
99 clear() => null; | |
100 remove(_) => null; | |
101 containsKey(_) => false; | |
102 containsValue(_) => false; | |
103 addAll(_) => null; | |
104 forEach(_) => null; | |
105 putIfAbsent(_, __) => null; | |
106 } | 86 } |
OLD | NEW |