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
TracMikeLTracMikeL 

Hide/Show Fields

Hey Guys,

 

I have the following VF code. I want to render the inputfield when the selectlist selectoptions is empty. And if its not empty show the selectlist only.

 

is this possible?

 

 

            <apex:pageBlockSection collapsible="false" columns="2" id="MappingValues">
                <apex:inputField id="TargetValue" value="{!Mapping.Value_Out__c}" required="true" />
                <apex:selectList id="TargetPickList" value="{!Mapping.Value_Out__c}" size="1">
                    <apex:selectOptions value="{!TargetPickList}"/>
                </apex:selectList>
            </apex:pageBlockSection>                     

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

Try rendered attribute as mentioned below

 

<apex:pageBlockSection collapsible="false" columns="2" id="MappingValues">
<apex:inputField id="TargetValue" value="{!Mapping.Value_Out__c}" required="true" rendered="{!IF(TargetPickList.size=0 , true, false)}"/>
<apex:selectList id="TargetPickList" value="{!Mapping.Value_Out__c}" size="1" rendered="{!IF(TargetPickList.size>0 , true, false)}">
<apex:selectOptions value="{!TargetPickList}"/>
</apex:selectList>
</apex:pageBlockSection>

 

 

With Best,

crmtech21

All Answers

AhmedPotAhmedPot

Hi,

 

you can use action support to re render the section or page block and use rendered condition in your input field.

 

<apex:pageblock id="theForm">
<apex:pageBlockSection collapsible="false" columns="2" id="MappingValues">
                <apex:inputField id="TargetValue" value="{!Mapping.Value_Out__c}" required="true" rendered="{!if(Mapping.Value_Out__c!='',true,false)}" />
                <apex:selectList id="TargetPickList" value="{!Mapping.Value_Out__c}" size="1">
                    <apex:selectOptions value="{!TargetPickList}"/>
                </apex:selectList>
<apex:actionSupport reRender="theForm" event="onchange"/>
  </apex:pageBlockSection>  
<apex:pageblock>

 

Hope this helps.

 

Thanks,

Ahmed

Prafull G.Prafull G.

Try rendered attribute as mentioned below

 

<apex:pageBlockSection collapsible="false" columns="2" id="MappingValues">
<apex:inputField id="TargetValue" value="{!Mapping.Value_Out__c}" required="true" rendered="{!IF(TargetPickList.size=0 , true, false)}"/>
<apex:selectList id="TargetPickList" value="{!Mapping.Value_Out__c}" size="1" rendered="{!IF(TargetPickList.size>0 , true, false)}">
<apex:selectOptions value="{!TargetPickList}"/>
</apex:selectList>
</apex:pageBlockSection>

 

 

With Best,

crmtech21

This was selected as the best answer
TracMikeLTracMikeL

Thanks alot! That worked beautifully. Gold star for you! :)