You need to sign in to do that
Don't have an account?
Radio button in data table select only one
Hi,
I would like to have radio buttons in each row of a dataTable and the user must be allowed to select only one. That is, the previously selected radio button should be reset when a new radio button on a different row is selected.
Please suggest.
Also please suggest how to assign value to a variable in the wrapper class from the <input type="radio" >
I tried <apex:param but it did not seem to work
<input type="radio" name="test" onclick="return confirmSubmit();" value="1">
</input>
I found a workaround
<script>
function confirmSubmit()
{
var doSelect = confirm('Are you sure you wish to assign?');
if(doSelect)
{
alert(doSelect);
f1();
}
return doSelect;
}
</script>
<apex:dataTable value="{!ContactWrapper}" var="c" >
<apex:inputCheckBox value="{!c.checked}" onclick="return confirmSubmit();" />
<apex:actionFunction name="f1" action="{!methodOne}" rerender="form" >
<apex:param name="conid" value="{!c.ContactId}" id="param1"/>
</apex:actionFunction>
</apex:dataTable>
public void methodOne()
{
String selcontactid = System.currentPagereference().getParameters().get('conid');
for(wrapper w:ContactWrapper)
{
if(w.ContactInfo.id==selcontactid)
{
w.checked=true;
assignButton=true;
}
else
{
w.checked=false;
}
}
}
public class wrapper
{
public Contact ContactInfo{get;set;}
public String ContactId{get;set;}
public Boolean checked{get;set;}
public wrapper(Contact c)
{
this.ContactInfo=c;
this.checked=false;
this.ContactId=c.id;
}
}
This should work but the problem is the last row in the dataTable is getting checked irrespective of which row i select.
Param tag is assigning the last row's id as the value. I can't figure out why...
Please suggest