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
Nikhil SomvanshiNikhil Somvanshi 

Using Rendered Attribute

Hello Community,

I am very confused on how Rendered attribute would work for the case: I want to display a Field B only if another Field A (which is a Picklist of 'Yes' and 'No') is set as Yes, on my Visualforce page. I want someone please share a basic example on how to go about it.

Best Answer chosen by Nikhil Somvanshi
Raj VakatiRaj Vakati
Ohh got it .. Here is the final code 

 
<apex:page StandardController="Account" >
    <apex:form >
        <apex:PageBlock title="Check Rendered on Account">
           
            
            
            
            
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!account.Name}"/>
                <apex:inputField value="{!account.Phone}"/>
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="{!$ObjectType.Account.fields.Active__c.label}" for="act"/>      
                    <apex:actionRegion >
                        <apex:inputField value="{!account.Active__c}" id="act">
                            <apex:actionSupport event="onchange" reRender="ajax" immediate="false"/>
                        </apex:inputField>
                    </apex:actionRegion>
                    
                </apex:pageBlockSectionItem>
                 <apex:outputPanel id="ajax">
                <apex:pageBlockSection title="Will render" id="idr" rendered="{!account.Active__c == 'Yes'}">
                    
                    <apex:inputField value="{!account.Amount__c}"/>
                    
                </apex:pageBlockSection>
            </apex:outputPanel>
            </apex:pageBlockSection>
            
            
        </apex:Pageblock>
    </apex:form>
</apex:page>

 

All Answers

Raj VakatiRaj Vakati

Here is the code for you 
 
<apex:page standardController="Contact">
    <apex:form>
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:inputField value="{!contact.Field_B__c}">
                    <apex:actionSupport event="onchange" reRender="ajaxrequest" />
                </apex:inputField>
            </apex:pageBlockSection>
            <apex:outputPanel id="ajaxrequest">
                
                <apex:pageBlockSection title=" Test" id="ppc" rendered="{!contact.Field_B__c == 'Yes'}">
                    <apex:inputField value="{!contact.Email}"/>
                    
                </apex:pageBlockSection>
            </apex:outputPanel>
        </apex:pageBlock>
    </apex:form>
</apex:page>



 
Nikhil SomvanshiNikhil Somvanshi
Thanks Raj for the prompt revert. Using your guidance i tried manifesting a quick sample but doesn't look like it's working. Can you see below:
<apex:page StandardController="Account" >
<apex:form >
<apex:PageBlock title="Check Rendered on Account">

<apex:pageBlockSection columns="1">
<apex:inputField value="{!Account.Name}"/>
<apex:inputField value="{!Account.Phone}"/>

<apex:inputField value="{!Account.Active__c}">
<apex:actionSupport event="Onchange" reRender="ajax"/>
</apex:inputField>
</apex:pageBlockSection>

<apex:outputPanel id="ajax">
<apex:pageBlockSection title="Will render" id="idr" rendered="{!Account.Active__c == 'Yes'}">

<apex:inputField value="{!Account.Amount__c}"/>

</apex:pageBlockSection>
</apex:outputPanel>

</apex:Pageblock>
</apex:form>
</apex:page>

 
Raj VakatiRaj Vakati
Update code is here. On apex: actionSupport event name is wrong.It is not Onchange .its onchange

 
<apex:page StandardController="Account" >
    <apex:form >
        <apex:PageBlock title="Check Rendered on Account">
            
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!account.Name}"/>
                <apex:inputField value="{!account.Phone}"/>
                
                <apex:inputField value="{!account.Active__c}">
                    <apex:actionSupport event="onchange" reRender="ajax"/>
                </apex:inputField>
            </apex:pageBlockSection>
            
            <apex:outputPanel id="ajax">
                <apex:pageBlockSection title="Will render" id="idr" rendered="{!account.Active__c == 'Yes'}">
                    
                    <apex:inputField value="{!account.Amount__c}"/>
                    
                </apex:pageBlockSection>
            </apex:outputPanel>
            
        </apex:Pageblock>
    </apex:form>
</apex:page>

 
Nikhil SomvanshiNikhil Somvanshi
Raj, when I change the value of Active field to Yes (<apex:inputField value="{!account.Active__c}">) , i am not able to see the desired (<apex:inputField value="{!account.Amount__c}") on the page. Are we missing something here ? Can you please compile this code on your own and see if there is a problem in this.
Raj VakatiRaj Vakati
Ohh got it .. Here is the final code 

 
<apex:page StandardController="Account" >
    <apex:form >
        <apex:PageBlock title="Check Rendered on Account">
           
            
            
            
            
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!account.Name}"/>
                <apex:inputField value="{!account.Phone}"/>
                
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="{!$ObjectType.Account.fields.Active__c.label}" for="act"/>      
                    <apex:actionRegion >
                        <apex:inputField value="{!account.Active__c}" id="act">
                            <apex:actionSupport event="onchange" reRender="ajax" immediate="false"/>
                        </apex:inputField>
                    </apex:actionRegion>
                    
                </apex:pageBlockSectionItem>
                 <apex:outputPanel id="ajax">
                <apex:pageBlockSection title="Will render" id="idr" rendered="{!account.Active__c == 'Yes'}">
                    
                    <apex:inputField value="{!account.Amount__c}"/>
                    
                </apex:pageBlockSection>
            </apex:outputPanel>
            </apex:pageBlockSection>
            
            
        </apex:Pageblock>
    </apex:form>
</apex:page>

 
This was selected as the best answer
Nikhil SomvanshiNikhil Somvanshi
Works well Raj. Thank you. Can you please also explain what wonders did the ActionRegion attribute do to this?