_CheckBoxMixin.js.uncompressed.js 2.5 KB

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