Fix doesn't work with brackets in names...
Since I am submitting hashes to the server my form elements are name like hashname[key]. The proposed solution produces an exception since the CSS selector than reads: input[name=hashname[key]] which cannot be parsed.
Does anyone know how to escape that stuff I tried name.replace(/\[/g,'\\[') and variants therof but they don't seem to work.
2.0.1 radio setValue does not propagate to group
Quote:
Originally Posted by
brian.moeskau
Code:
getGroupValue : function(){
var p = this.el.up('form') || Ext.getBody();
return p.child('input[name='+this.el.dom.name+']:checked', true).value;
},
// private
onClick : function(){
if(this.el.dom.checked != this.checked){
var p = this.el.up('form') || Ext.getBody();
var els = p.select('input[name='+this.el.dom.name+']');
els.each(function(el){
if(el.dom.id == this.id){
this.setValue(true);
}else{
Ext.getCmp(el.dom.id).setValue(false);
}
}, this);
}
}
I've committed this fix to SVN for both 1.1 and 2.0 (1.1 uses Ext.get(document.body) instead of Ext.getBody()).
I am using this code in 2.0.1, and I experienced a difficult problem as a side effect. In a dialog window, I was populating a radio group by calling setValue on the selected radio button, and I assumed that the other radio buttons with the same name would have their values set to false. That was my error.
But what made this difficult to find was the fact that clicking on a radio button would propagate changes to the values of other radio buttons and compoents, but only if the value of the radio button clicked on was different from the value of the component. Consequently, by initially setting the value of only the selected radio button, this prevented the 'check' event from being triggered on other radio buttons whose components happened to have a true value.
The easy workaround is to set all of the radio buttons individually. I see in the latest version (2.0.2?) that we can also set the value of any radio to the string name used in the inputValue of the selected radio in the group. That will be more convenient, but it is still not clear from the docs whether all the other radio buttons will be set to false.
Quote:
setValue( value {String/Boolean} ) : void
Sets either the checked/unchecked status of this Radio, or, if a string value is passed, checks a sibling Radio of the same name whose value is the value specified.
It would be most convenient and least surprising if the Radio component acted like HTML radio buttons, by enforcing the group constraint that only a single radio button in a group is checked.