| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/dom-attr", |
| 5 |
"dojo/_base/lang", |
| 6 |
"dojo/query!css2", |
| 7 |
"../registry" |
| 8 |
], function(array, declare, domAttr, lang, query, registry){ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
return declare("dijit.form._RadioButtonMixin", null, { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
type: "radio", |
| 21 |
|
| 22 |
_getRelatedWidgets: function(){ |
| 23 |
|
| 24 |
var ary = []; |
| 25 |
query("input[type=radio]", this.focusNode.form || this.ownerDocument).forEach( |
| 26 |
lang.hitch(this, function(inputNode){ |
| 27 |
if(inputNode.name == this.name && inputNode.form == this.focusNode.form){ |
| 28 |
var widget = registry.getEnclosingWidget(inputNode); |
| 29 |
if(widget){ |
| 30 |
ary.push(widget); |
| 31 |
} |
| 32 |
} |
| 33 |
}) |
| 34 |
); |
| 35 |
return ary; |
| 36 |
}, |
| 37 |
|
| 38 |
_setCheckedAttr: function( value){ |
| 39 |
|
| 40 |
this.inherited(arguments); |
| 41 |
if(!this._created){ |
| 42 |
return; |
| 43 |
} |
| 44 |
if(value){ |
| 45 |
array.forEach(this._getRelatedWidgets(), lang.hitch(this, function(widget){ |
| 46 |
if(widget != this && widget.checked){ |
| 47 |
widget.set('checked', false); |
| 48 |
} |
| 49 |
})); |
| 50 |
} |
| 51 |
}, |
| 52 |
|
| 53 |
_getSubmitValue: function( value){ |
| 54 |
return value == null ? "on" : value; |
| 55 |
}, |
| 56 |
|
| 57 |
_onClick: function( e){ |
| 58 |
if(this.checked || this.disabled){ |
| 59 |
e.stopPropagation(); |
| 60 |
e.preventDefault(); |
| 61 |
return false; |
| 62 |
} |
| 63 |
|
| 64 |
if(this.readOnly){ |
| 65 |
e.stopPropagation(); |
| 66 |
e.preventDefault(); |
| 67 |
array.forEach(this._getRelatedWidgets(), lang.hitch(this, function(widget){ |
| 68 |
domAttr.set(this.focusNode || this.domNode, 'checked', widget.checked); |
| 69 |
})); |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
var canceled = false; |
| 77 |
var previouslyCheckedButton; |
| 78 |
|
| 79 |
array.some(this._getRelatedWidgets(), function(radioButton){ |
| 80 |
if(radioButton.checked){ |
| 81 |
previouslyCheckedButton = radioButton; |
| 82 |
return true; |
| 83 |
} |
| 84 |
return false; |
| 85 |
}); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
this.checked = true; |
| 91 |
previouslyCheckedButton && (previouslyCheckedButton.checked = false); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
if(this.onClick(e) === false || e.defaultPrevented){ |
| 96 |
canceled = true; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
this.checked = false; |
| 101 |
previouslyCheckedButton && (previouslyCheckedButton.checked = true); |
| 102 |
|
| 103 |
if(canceled){ |
| 104 |
e.preventDefault(); |
| 105 |
}else{ |
| 106 |
this.set('checked', true); |
| 107 |
} |
| 108 |
|
| 109 |
return !canceled; |
| 110 |
} |
| 111 |
}); |
| 112 |
}); |