source: Dev/trunk/src/client/dijit/form/_CheckBoxMixin.js

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.5 KB
Line 
1define([
2        "dojo/_base/declare", // declare
3        "dojo/dom-attr" // domAttr.set
4], function(declare, domAttr){
5
6        // module:
7        //              dijit/form/_CheckBoxMixin
8
9        return declare("dijit.form._CheckBoxMixin", null, {
10                // summary:
11                //              Mixin to provide widget functionality corresponding to an HTML checkbox
12                //
13                // description:
14                //              User interacts with real html inputs.
15                //              On onclick (which occurs by mouse click, space-bar, or
16                //              using the arrow keys to switch the selected radio button),
17                //              we update the state of the checkbox/radio.
18                //
19
20                // type: [private] String
21                //              type attribute on `<input>` node.
22                //              Overrides `dijit/form/Button.type`.  Users should not change this value.
23                type: "checkbox",
24
25                // value: String
26                //              As an initialization parameter, equivalent to value field on normal checkbox
27                //              (if checked, the value is passed as the value when form is submitted).
28                value: "on",
29
30                // readOnly: Boolean
31                //              Should this widget respond to user input?
32                //              In markup, this is specified as "readOnly".
33                //              Similar to disabled except readOnly form values are submitted.
34                readOnly: false,
35
36                // aria-pressed for toggle buttons, and aria-checked for checkboxes
37                _aria_attr: "aria-checked",
38
39                _setReadOnlyAttr: function(/*Boolean*/ value){
40                        this._set("readOnly", value);
41                        domAttr.set(this.focusNode, 'readOnly', value);
42                },
43
44                // Override dijit/form/Button._setLabelAttr() since we don't even have a containerNode.
45                // Normally users won't try to set label, except when CheckBox or RadioButton is the child of a dojox/layout/TabContainer
46                _setLabelAttr: undefined,
47
48                _getSubmitValue: function(/*String*/ value){
49                        return (value == null || value === "") ? "on" : value;
50                },
51
52                _setValueAttr: function(newValue){
53                        newValue = this._getSubmitValue(newValue);      // "on" to match browser native behavior when value unspecified
54                        this._set("value", newValue);
55                        domAttr.set(this.focusNode, "value", newValue);
56                },
57
58                reset: function(){
59                        this.inherited(arguments);
60                        // Handle unlikely event that the <input type=checkbox> value attribute has changed
61                        this._set("value", this._getSubmitValue(this.params.value));
62                        domAttr.set(this.focusNode, 'value', this.value);
63                },
64
65                _onClick: function(/*Event*/ e){
66                        // summary:
67                        //              Internal function to handle click actions - need to check
68                        //              readOnly, since button no longer does that check.
69                        if(this.readOnly){
70                                e.stopPropagation();
71                                e.preventDefault();
72                                return false;
73                        }
74                        return this.inherited(arguments);
75                }
76        });
77});
Note: See TracBrowser for help on using the repository browser.