I have a row of radio buttons that are created in the xml
<row>
<cell></cell>
<cell type="ra_str" name="week1"></cell>
<cell type="ra_str" name="week1"></cell>
<cell type="ra_str" name="week1"></cell>
<cell type="ra_str" name="week1"></cell>
<cell type="ra_str" name="week1"></cell>
<cell image="../../images/date.gif"></cell>
</row>
I need to make sure that the user selects a radio value. Is there built in validation for radio buttons? I have not found that in the documentation. I’ve seen ways to set the validation for a column or by individual cell. Is there a way to validate by row? The examples I’ve seen with custom validation all works with columns.
Thanks
There is no such validation logic, but you can attach custom handler to some event
( onBeforeUpdate event of dataprocessor for example ) and check is some radio was checked from it
Thank you for the reply. I did create a custom validation that loops thru the rows and takes the values from the radio button columns, storing them in a temp array. The value returned for the radio buttons is 0 (unchecked) or 1 (checked) so I check each row to see if there is a checked radio from the values stored in the temp array. If a radio is not selected, I mark the row with a different color background and do not allow the form to submit.
I’ve included my code here to help others who may have a similar need. Mine is a treegrid with the children holding the radio buttons.
function validateRadio(){
// find each row that has more than 1 child
mygrid2.forEachRow(function(id){
// clear backgrounds
mygrid2.setRowColor(id,"");
if(mygrid2.hasChildren(id)>1){
// get the child's id
var test = mygrid2.getChildItemIdByIndex(id,0);
var tempArray = [];
// get the cell value for that child col 1-5 and push in to tempArray
for(var i=1; i<6; i++){
var val = mygrid2.cellById(test,i).getValue();
tempArray.push(val);
}
// test if value of 1 is in tempArray
if(1 in oc(tempArray)){
// passed validation
mygrid2.setRowColor(id,"");
} else {
// failed validation
mygrid2.setRowColor(id,"#eeb4b4");
}
}
});
}
// test for value in array (used in validateRadio to find if cell value set to 1)
function oc(a){
var o = {};
for(var i=0; i<a.length; i++){
o[a[i]] = ''
}
return o;
}