_CheckBoxMixin.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // summary:
  9. // Mixin to provide widget functionality corresponding to an HTML checkbox
  10. return declare("dijit.form._CheckBoxMixin", null, {
  11. // summary:
  12. // Mixin to provide widget functionality corresponding to an HTML checkbox
  13. //
  14. // description:
  15. // User interacts with real html inputs.
  16. // On onclick (which occurs by mouse click, space-bar, or
  17. // using the arrow keys to switch the selected radio button),
  18. // we update the state of the checkbox/radio.
  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. // value: String
  25. // As an initialization parameter, equivalent to value field on normal checkbox
  26. // (if checked, the value is passed as the value when form is submitted).
  27. value: "on",
  28. // readOnly: Boolean
  29. // Should this widget respond to user input?
  30. // In markup, this is specified as "readOnly".
  31. // Similar to disabled except readOnly form values are submitted.
  32. readOnly: false,
  33. // aria-pressed for toggle buttons, and aria-checked for checkboxes
  34. _aria_attr: "aria-checked",
  35. _setReadOnlyAttr: function(/*Boolean*/ value){
  36. this._set("readOnly", value);
  37. domAttr.set(this.focusNode, 'readOnly', value);
  38. },
  39. // Override dijit.form.Button._setLabelAttr() since we don't even have a containerNode.
  40. // Normally users won't try to set label, except when CheckBox or RadioButton is the child of a dojox.layout.TabContainer
  41. _setLabelAttr: undefined,
  42. postMixInProperties: function(){
  43. if(this.value == ""){
  44. this.value = "on";
  45. }
  46. this.inherited(arguments);
  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. });