source: Dev/trunk/src/client/qed-client/widgets/_ComplexValueMixin.coffee @ 492

Last change on this file since 492 was 492, checked in by hendrikvanantwerpen, 11 years ago
  • Enable/disable buttons on content change.
  • One place to do date formatting, because it was going wrong again.
  • Serialize questions in survey properly.
  • _ComplexValueMixin consumes submit events, but does trigger outer forms if present.
  • Trigger dialog show/hide for login only after previous effect is finished.
  • Check that documents are actually valid, not just that validator returned a result.
  • Validate email and timestamp formats.
  • Prepared for live runs.
File size: 1.8 KB
Line 
1define [
2    "dijit/_Container",
3    "dijit/form/_FormMixin",
4    "dijit/registry",
5    "dojo/_base/array",
6    "dojo/_base/declare",
7    "dojo/_base/event",
8    "dojo/on"
9], (_Container, _FormMixin, registry, array, declare, event, _on) ->
10    declare [_Container,_FormMixin],
11        name: ""
12        value: null
13        disabled: false
14        readOnly: false
15
16        postCreate: () ->
17            @inherited arguments
18            if @domNode.tagName.toLowerCase() isnt "form"
19                console.warn "Not scoping a _ComplexValueMixin in a
20                        form element can cause name clashes. E.g.
21                        radio buttons might stop working correctly.
22                        It is recommended to use <form> as the root
23                        element in your template for", @declaredClass
24            @own ( _on @domNode, 'submit', (evt) => @_handleSubmit evt )
25
26        _setDisabledAttr: (value) ->
27            @_set "disabled", value
28            array.forEach @_getDescendantFormWidgets(), (child) =>
29                child.set "disabled", value
30
31        _setReadOnlyAttr: (value) ->
32            @_set "readOnly", value
33            array.forEach @_getDescendantFormWidgets(), (child) =>
34                child.set "readOnly", value
35
36        focus: () ->
37            children = @_getDescendantFormWidgets()
38            children[0].focus() if children.length > 0
39
40        _handleSubmit: (evt) ->
41            node = @domNode
42            until not node or ( widget and
43                                typeof widget._onSubmit is "function" )
44                node = node.parentNode
45                widget = registry.byNode node if node
46            widget._onSubmit(evt) if widget
47            # we always stop the event, since this is a widget after all
48            event.stop evt if evt
49            false
Note: See TracBrowser for help on using the repository browser.