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
SeattleSFDCSeattleSFDC 

InputTextArea Required based on previous response

I'm trying to make an InputTextArea required based on a previous response.  To be specific, if the onSiteSupport radiobutton selection = 'Yes' then make onSiteSupportCoverage InputTextArea required, if the response is 'No' then onSiteSupportCoverage is not required.  What's the easiest way to accomplish this?  I tried an inline IF statement, but it's not working.

<div class="questionRadio"><span class="required">*</span> Onsite customer support?</div>
                    <div class="questionRadioInput">
                        <apex:selectRadio value="{!onSiteSupport}" id="onsite" required="true">
                            <apex:selectOption itemValue="Yes" itemLabel="Yes"/>
                            <apex:selectOption itemValue="No" itemLabel="No"/>
                        </apex:selectRadio>
                        <apex:message styleClass="customError" for="onsite"/>
                    </div>
                    
                    <div class="question"> If yes, then where?</div>
                    <div class="longInputWrapper">
                        <apex:inputTextArea value="{!onSiteSupportCoverage}" styleClass="longInput" id="onSiteSupportCoverage" required="{!If(onSiteSupport == 'Yes',true,false)}"/>
                        <apex:message styleClass="customError" for="onSiteSupportCoverage"/>
                    </div>


Sfdc CloudSfdc Cloud
Hi Seattle,
 When you are selecting radiobutton that time value of SelectOption is not passing into controller.What you can do is either create a button to pass the value to controller or you can use onselect attribute.
I have created one example in my org its working fine.Have a look 
VIsualforce Page

<apex:page standardController="Contact" extensions="con">
    <apex:form id="changeDescription">
    <apex:pageBlock >
            <apex:selectRadio value="{!country}">
            <apex:selectOptions value="{!items}"/>
            </apex:selectRadio>
            <apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
            <apex:outputPanel id="out">
          <apex:actionstatus id="status" startText="testing..."> 
             <apex:facet name="stop"> 
               <apex:outputPanel > 
                  <p>You have selected:</p> 
                 <apex:outputText value="{!country}"/> 
                 <apex:inputTextarea id="newDesc" value="{!contact.description}" required="{!If(country == 'US',true,false)}"/><p/>
                <apex:message for="newDesc"/>
                <apex:commandButton value="Save" action="{!save}"/>
              </apex:outputPanel> 
            </apex:facet> 
          </apex:actionstatus> 
     </apex:outputPanel> 
    </apex:pageBlock>
    </apex:form>
</apex:page>

Controller

public class con {
    public con(ApexPages.StandardController controller) {

    }
    String country = null;
         
    public PageReference test() {
        return null;
    }
                
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>(); 
        options.add(new SelectOption('US','US')); 
        options.add(new SelectOption('CANADA','Canada')); 
        options.add(new SelectOption('MEXICO','Mexico')); return options; 
    }
                   
    public String getCountry() {
        return country;
    }
                    
    public void setCountry(String country) { this.country = country; }
}
I have used apex:message to check the error message on apex:inputtextArea field..

Hope this helps !!!
If this answer helps,please mark it as best answer to help others :)
Thanks