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
Mit PatelMit Patel 

Need Dependency for Text Box Based on Pick-list

I'm trying to make it so a field appears only when another field is answered a certain way.

For example:
I have a picklist that the user will choose  "Yes / No". Field name "Pan card "
If they choose Yes, then I want a text field to appear so they can provide Pan card Number.
If they choose No, then I don't want the field to appear.
Please Let Me Know either of possibilities (Configuration / Development).

Either Through VF,APex, or Customization.

Please let me know if this is possible, and how I would go about doing this. Thanks!

NIKHIL_SFDCNIKHIL_SFDC

Hi Patel, 

 

This is not possible in salesforce, you can put a validation rule like no one can field data in 'Pan card Number' without choosing Yes in "Pan card".

 

Validation Rule would be like-

 

AND(IF( ISPICKVAL( Pan_card__c , 'Yes' ) , ISBLANK( Pan_card_Number__c )=true, null ))

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved, so that others may take help from this.

Chamil MadusankaChamil Madusanka

Patel, Are you trying to achieve your requirement via standard page or visualforce page?

 

If it is standard page Nikhil's approach is correct. You can achieve your requirement via visualforce page too.

 

Visualfroce example

<apex:page controller="TestPage10Controller">  
    <apex:form >
    <apex:pageBlock >
            <apex:pageBlockSection >
            <apex:pageBlockSectionItem >
            <apex:outputLabel value="Selection"></apex:outputLabel>
        <apex:selectList value="{!selectedValue}" size="1">
         <apex:selectOption itemLabel="--None--" itemValue="--None--"></apex:selectOption>
            <apex:selectOption itemLabel="Yes" itemValue="Yes"></apex:selectOption>
            <apex:selectOption itemLabel="No" itemValue="No"></apex:selectOption>
            <apex:actionSupport event="onchange" reRender="iText1,iText2"/>
        </apex:selectList>
        </apex:pageBlockSectionItem>
        
        <apex:pageBlockSectionItem >
        <apex:outputLabel value="Field 1"></apex:outputLabel>
        <apex:inputText id="iText1" disabled="{!selectedValue == 'Yes' || selectedValue == '--None--'}" />
        </apex:pageBlockSectionItem>
        
        <apex:pageBlockSectionItem >
        <apex:outputLabel value="Field 2"></apex:outputLabel>
        <apex:inputText id="iText2" disabled="{!selectedValue == 'No' || selectedValue == '--None--'}" />
        </apex:pageBlockSectionItem>
        
        </apex:pageBlockSection>
     </apex:pageBlock>   
        
    </apex:form>
  </apex:page>

 

public with sharing class TestPage10Controller 
{
   
    public String selectedValue{get;set;}
    
    public TestPage10Controller ()
    {
        selectedValue = '--None--';
        
    }
    
    
}

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.