1 | define [ |
---|
2 | "dijit/_Container", |
---|
3 | "dijit/form/_FormMixin", |
---|
4 | "dojo/_base/array", |
---|
5 | "dojo/_base/declare", |
---|
6 | "dojo/_base/event" |
---|
7 | ], (_Container, _FormMixin, array, declare, event) -> |
---|
8 | declare [_Container,_FormMixin], |
---|
9 | name: "" |
---|
10 | value: null |
---|
11 | disabled: false |
---|
12 | readOnly: false |
---|
13 | |
---|
14 | postCreate: () -> |
---|
15 | @inherited arguments |
---|
16 | if @domNode.tagName.toLowerCase() isnt "form" |
---|
17 | console.warn "Not scoping a _ComplexValueMixin in a |
---|
18 | form element can cause name clashes. E.g. |
---|
19 | radio buttons might stop working correctly. |
---|
20 | It is recommended to use <form> as the root |
---|
21 | element in your template for", @declaredClass |
---|
22 | |
---|
23 | _setDisabledAttr: (value) -> |
---|
24 | @_set "disabled", value |
---|
25 | array.forEach @_getDescendantFormWidgets(), (child) => |
---|
26 | child.set "disabled", value |
---|
27 | |
---|
28 | _setReadOnlyAttr: (value) -> |
---|
29 | @_set "readOnly", value |
---|
30 | array.forEach @_getDescendantFormWidgets(), (child) => |
---|
31 | child.set "readOnly", value |
---|
32 | |
---|
33 | focus: () -> |
---|
34 | children = @_getDescendantFormWidgets() |
---|
35 | children[0].focus() if children.length > 0 |
---|
36 | |
---|
37 | onSubmit: (e) => |
---|
38 | # since this widget is used to create more complex |
---|
39 | # widgets within other forms, the onSubmit must either be |
---|
40 | # ignored or propagated, but not handled here. |
---|
41 | event.stop e if e |
---|
42 | false |
---|
43 | |
---|
44 | _onSubmit: (e) => |
---|
45 | # since this widget is used to create more complex |
---|
46 | # widgets within other forms, the onSubmit must either be |
---|
47 | # ignored or propagated, but not handled here. |
---|
48 | event.stop if e |
---|
49 | false |
---|