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
Will Jones 18Will Jones 18 

Visualforce to hide section based on picklist (contact manager edition)

Anyone have sample code for an account visualforce page that will hide a section based on a picklist value? This is for a contact manager edition so no apex is allowed. I would need this to be hidden on the edit page and the saved page of the account Thanks!
Pramodh KumarPramodh Kumar
here is the small snippet code for rerender the fields based on the picklist value. 

In my scenario, I took accountSource field, if it is equal to Web then only you can able to see the Phone field.

Let me know if you still have an issue.
<apex:page cache="true" expires="600" standardController="account">
    <apex:form >
    <apex:pageBlock id="block">
    <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
    </apex:pageBlockButtons>
        <apex:pageBlockSection >
            <apex:inputField value="{!account.Name}"/>
            <apex:inputfield value="{!account.AccountSource}">
                <apex:actionSupport event="onchange" reRender="block"/>
            </apex:inputfield>
        </apex:pageBlockSection>
        <apex:pageBlockSection rendered="{!if(account.AccountSource =='Web',true,false)}">
            <apex:inputField value="{!account.Phone}"/>
            
        </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
    
</apex:page>

Thanks,
Pramodh.
Will Jones 18Will Jones 18
Thanks Pramodh. How about making an entire section disappear?
Pramodh KumarPramodh Kumar
If you change the picklist value it will rerender the entire block and display the section based on the picklist value. Thanks, Pramodh.
Ajay K DubediAjay K Dubedi
Hi Will Jones,

Try the following code as per your requirement for the particular section to be displayed on the select of the depending picklist.

<----------Controller---------->
public class dependcustompicklist {

    public String selectcity { get; set; }

    public String selectcountry { get; set; }
    
    public Boolean test {get;set;}
    
    public dependcustompicklist(){
    }
    
    public void testFunction(){
        test = true;
    }
    
    public list <SelectOption> getcountry()
    {
        list <SelectOption> opt = new list <SelectOption> ();
        opt.add(new SelectOption ('','Select'));
        opt.add(new SelectOption ('India','India'));
        opt.add(new SelectOption ('US','US'));
        opt.add(new SelectOption ('UK','UK'));
        return opt;
    }
    
        public list <SelectOption> getcity()
    {
        list <SelectOption> opt1 = new list <SelectOption> ();
        if(selectcountry != null && test != false)
            {
                if(selectcountry == 'India')
                {
                opt1.add(new SelectOption ('','Select'));
                opt1.add(new SelectOption ('Kanpur','Kanpur'));
                opt1.add(new SelectOption ('Ghaziabad','Ghaziabad'));
                opt1.add(new SelectOption ('Noida','Noida'));
                }
                if(selectcountry == 'US')
                {
                opt1.add(new SelectOption ('','Select'));
                opt1.add(new SelectOption ('Washington DC','Washington DC'));
                opt1.add(new SelectOption ('New York','New York'));
                opt1.add(new SelectOption ('Los Angeles','Los Angeles'));
                }
                if(selectcountry == 'UK')
                {
                opt1.add(new SelectOption ('','Select'));
                opt1.add(new SelectOption ('London','London'));
                opt1.add(new SelectOption ('Paris','Paris'));
                //opt1.add(new SelectOption ('',''));
                }
            }
        return opt1;
    }
}
<----------Page-------------->
<apex:page controller="dependcustompicklist">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Country Name">
                <apex:selectList value="{!selectcountry}" label="Country" size="1">
                    <apex:actionSupport action="{!testFunction}" event="onchange" reRender="cuMain"/>
                    <apex:selectOptions value="{!country}" rendered="true" id="test"/>    
                </apex:selectList>
            </apex:pageBlockSection>
            <apex:outputPanel id="cuMain">
            <apex:pageBlockSection title="City Name" id="cu" rendered="{!test}">
                <apex:selectList value="{!selectcity}" label="City" size="1" disabled="{!ISNULL(country)}">
                    <apex:selectOptions value="{!city}" rendered="true"/>
                </apex:selectList>
            </apex:pageBlockSection>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Thanks