1 define("dijit/form/_RadioButtonMixin", [
2 "dojo/_base/array", // array.forEach
3 "dojo/_base/declare", // declare
4 "dojo/dom-attr", // domAttr.set
5 "dojo/_base/event", // event.stop
6 "dojo/_base/lang", // lang.hitch
8 "../registry" // registry.getEnclosingWidget
9 ], function(array, declare, domAttr, event, lang, query, registry){
12 // dijit/form/_RadioButtonMixin
14 return declare("dijit.form._RadioButtonMixin", null, {
16 // Mixin to provide widget functionality for an HTML radio button
18 // type: [private] String
19 // type attribute on `<input>` node.
20 // Users should not change this value.
23 _getRelatedWidgets: function(){
24 // Private function needed to help iterate over all radio buttons in a group.
26 query("input[type=radio]", this.focusNode.form || this.ownerDocument).forEach( // can't use name= since query doesn't support [] in the name
27 lang.hitch(this, function(inputNode){
28 if(inputNode.name == this.name && inputNode.form == this.focusNode.form){
29 var widget = registry.getEnclosingWidget(inputNode);
39 _setCheckedAttr: function(/*Boolean*/ value){
40 // If I am being checked then have to deselect currently checked radio button
41 this.inherited(arguments);
42 if(!this._created){ return; }
44 array.forEach(this._getRelatedWidgets(), lang.hitch(this, function(widget){
45 if(widget != this && widget.checked){
46 widget.set('checked', false);
52 _getSubmitValue: function(/*String*/ value){
53 return value === null ? "on" : value;
56 _onClick: function(/*Event*/ e){
57 if(this.checked || this.disabled){ // nothing to do
61 if(this.readOnly){ // ignored by some browsers so we have to resync the DOM elements with widget values
63 array.forEach(this._getRelatedWidgets(), lang.hitch(this, function(widget){
64 domAttr.set(this.focusNode || this.domNode, 'checked', widget.checked);
68 return this.inherited(arguments);