1

I have a vf page with radiobuttons. This is rendered only when a condition satisfied. The radiobuttons need to be mandatory only when it is rendered. But the problem is even if the radio options are not visible, it gives the error - that radio option must be selected. Here is the code

<apex:outputPanel id="packageDelivery" rendered="{!IF(applicantInfo.Category__c=='Student (F)',True,False)}">                               
 <div class="form-row">
 <div class="form-label top"><strong>How should we send Package?<span class="required">*</span></strong></div>
 <div class="form-field">
      <apex:selectRadio id="Package_Delivery" value="{!selectedPackageDelivery}" required="true">
          <apex:selectOptions value="{!listPackageDelivery}" />
      </apex:selectRadio>
 </div>    
 </div>
</apex:outputPanel> 

I tried to change the required="true" to required="{!IF(applicantInfo.Category__c=='Student (F)',True,False)}" but it throws error which I cannot capture.

please help. how to make a field required only when it is rendered!

1

I chose an alternate way of making it required through apex code validations on Save, instead of checking it at the visualforce component.

0

VisualForce:

<apex:form > <apex:pageMessages /> <apex:commandButton action="{!Save}" value="Save" immediate="false" /> <apex:inputField value="{!dummy.Category__c}" required="true" /> <apex:outputPanel id="packageDelivery" rendered="{!IF(dummy.Category__c=='Student (F)',True,False)}"> <apex:selectRadio id="Package_Delivery" value="{!selOpt}" required="{!dummy.Category__c=='Student (F)'}"> <apex:selectOptions value="{!listPackageDelivery}" /> </apex:selectRadio> </apex:outputPanel> </apex:form>

'Category__c' is just a regular text field on my custom object. My radio buttons are only considered required if Category__c is set to 'Student (F)'

  • Nope. it doesn't work too. – sfdcFanBoy Jun 3 '14 at 3:23
  • I chose an alternate way of making it required through apex code validations on Save, instead of checking it at the visualforce component. – sfdcFanBoy Jun 3 '14 at 7:16
  • I just tried to reproduce your situation and it works fine. I modified my answer to show my entire code... – Christoph Jun 3 '14 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.