Dojo RadioButton, programmatically configure a group

I have a custom widget "MyWidget" with three radion buttons. I would like to be the same "group". If I set the "name" attribute in the radioobuttons in the template file, then the problem is that I create "MyWidget widgets" repeatedly, then all the radio cells use the same group.

I tried putting the "name" of the switch using

radioWifget.set('name', some_value) 

without success, and go directly to the DOM code with:

 dojo.query("INPUT[type='radio']", this.domNode).forEach( dojo.hitch(this, function(inputNode){ inputNode.name = 'perill_'+this.id; })); 

The second form sets the name attrbitue, but does not work as a group.

Any help.

Thanks in advance.


I apologize because I found the answer myself.

I will risk that someone will vote negatively for me, but would prefer to put a decision here, because maybe it can help someone other than me.

The solution is the switches in the "MyWidget" template, which should be enclosed in the "dijit.form.Form" widget. Thus, each β€œMyWidget” will have its own groups of radio volumes.

+7
source share
1 answer

I would select a custom FormValueWidget and mix _WidgetsInTemplateMixin, for example:

 declare([ "dojo/_base/declare", "dijit/form/_FormValueWidget", "dijit/_WidgetsInTemplateMixin", "dijit/form/RadioButton", "dojo/domReady!" ], function (declare, _FormValueWidget, _WidgetsInTemplateMixin) { return declare([_FormValueWidget, _WidgetsInTemplateMixin], { templateString: "<div><h2>Group of radioBtns '${name}'</h2>" + "<input type='radio' ${!nameAttrSetting} data-dojo-attach-point='focusNode' data-dojo-type='dijit/form/RadioButton' checked='checked' data-dojo-props='value:\"radio1\"'></input>" + "<input type='radio' ${!nameAttrSetting} data-dojo-type='dijit/form/RadioButton' data-dojo-props='value:\"radio2\"'></input>" + "<input type='radio' ${!nameAttrSetting} data-dojo-type='dijit/form/RadioButton' data-dojo-props='value:\"radio3\"'></input>" + "<input type='hidden' value='${value}'/>" + "</div>", _getValueAttr : function() { var selectedRadio = registry.findWidgets(this.domNode).filter(function(w){ return w.get("checked"); }).pop(); return selectedRadio.get("value"); } }); }); 

See an example here: http://jsfiddle.net/psoares/FdMEU/

+2
source

All Articles