function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DineshGuptaDineshGupta 

How to make a radio button required ?

Hi,

I am working on force.com sites, for that I need to incorporate some radio buttons and those must be required fields.
So i coded like below,

<td align="center" width="10%" style="vertical-align:middle;text-align:center;">
                <div>
                    <apex:outputPanel >
                        <div class="requiredInput">
                        <div class="requiredBlock"> </div>
                         <apex:selectRadio id="EQ2" onchange="renderPhyDet(this);" value="{!MemberEnrollment__c.Emp_Q2_Selected__c}">
                            <apex:selectOption itemValue="Yes" itemLabel="Yes"> </apex:selectOption>
                            <apex:selectOption itemValue="No" itemLabel="No"> </apex:selectOption>
                            </apex:selectRadio>
                        </div>
                    </apex:outputPanel> 
                </div> 
            </td>


Vertical line is showing but the page is not stopping the user if he dont select the radio button.  

User-added image

So I added required="true" label="Choose One" to the radio button, now the page is not being submitted even I submit the page. I think this "required" attribute is working but error message is not being displayed at the radio field which I have mentioned in the "label".
R Z KhanR Z Khan
I would set the value in the controller to a default. That way the suer is forced to chagne the value if its wrong
gyani19901.3956550919266765E12gyani19901.3956550919266765E12
Hi DineshGupta,
I think you set the defalut value in the controller and it show the required line in the page but when you save without selecting the option so its by default save.

Thanks & Regards
Gyanender Singh
http://www.mirketa.com
Panduranga GollaPanduranga Golla
 there is a required attribute in  SelectRadio component,then make it true ,it means mandatory for this radio button
sanjeev kakaraparthisanjeev kakaraparthi
DineshGupta.


Did you get the solution for it. i have the same problem which I'm unable to solve can you please let me know if you have idead
DineshGuptaDineshGupta

Hi sanjeev kakaraparthi,
I got the solution for it.  All i did is I have added  "<apex:pageMessages />" tag at the desired location along with the above code...
The code is like below,

<apex:pageMessages />
.. // Code //
.. // Code //
.. // Code //
.. // Code //
           <div >    
                    <apex:outputPanel >
                    <div class="requiredInput">
                    <div class="requiredBlock"> </div>
                        <apex:selectRadio id="EQ1" onchange="renderPhyDet(this);" value="{!MemberEnrollment__c.Emp_Q1_Selected__c}"                               required="true" label="Choose either YES or No for 1st health question">
                        <apex:selectOption itemValue="Yes" itemLabel="Yes" > </apex:selectOption>
                        <apex:selectOption itemValue="No" itemLabel="No" > </apex:selectOption>
                        </apex:selectRadio>
                    </div>    
                    </apex:outputPanel>
           </div>

Let me know if u still face the issue..

Regards,
Dinesh