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
Bhargav krishna 1Bhargav krishna 1 

Hide and Display the Custom Fields

Hi everyone,
Can we Hide and Display the Custom fields in the Custom Object when a particular value in the picklist is selected.
Thanks in advance.
Regards,
Bhargav.
Tavva Sai KrishnaTavva Sai Krishna
Hi Bhargav,

CUSTOM:
if you are in visualforce page you can do it by adding the render attribute on the custom fields. Also you can achieve the same for the Js & Jquery.

STANDARD;
For standard page you can write a trigger to change the layout of the page by changing the record type of the record. In this page layout (new PageLayout) you can hide the fieds.

Let me know if you need any help.

Thanks and Regards,
Sai Krishna Tavva.
Shailendra Singh ParmarShailendra Singh Parmar
If other field is picklist then you could create depedent picklist. https://help.salesforce.com/HTViewHelpDoc?id=fields_defining_field_dependencies.htm (https://help.salesforce.com/HTViewHelpDoc?id=fields_defining_field_dependencies.htm)

Other wise you could think about creating new record type and that record type has fields that you want to have.
 
JyothsnaJyothsna (Salesforce Developers) 
Hi,

Please check the below sample code for your requirement.

Visualforce Page:
 
<apex:page controller="sample">
    
    <apex:form >
    
    <apex:pageBlock >
        <apex:pageBlockSection columns="2">
            <apex:pageblockSectionItem >
                <apex:outputLabel value="State"/>
            </apex:pageblockSectionItem>        
            <apex:pageblockSectionItem >                
                <apex:selectList size="1" value="{!state}">
                    <apex:selectOptions value="{!states}"/>
                    <apex:actionSupport event="onchange" reRender="a"/>
                </apex:selectList>                
            </apex:pageblockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel value="City"/>
            </apex:pageblockSectionItem>            
            <apex:pageblockSectionItem >
                <apex:selectList size="1" value="{!city}" id="a">
                    <apex:selectOptions value="{!cities}"/>
                </apex:selectList>
            </apex:pageblockSectionItem>            
        </apex:pageBlockSection>        
    </apex:pageBlock>

    </apex:form>

</apex:page>

Controller:
 
public class sample
{
    public String state {get;set;}
    public String city {get;set;}

    public List<SelectOption> getStates()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('None','--- None ---'));        
        options.add(new SelectOption('TN','Tamil Nadu'));
        options.add(new SelectOption('KL','Kerala'));
        return options;
    } 
    
    public List<SelectOption> getCities()
    {
        List<SelectOption> options = new List<SelectOption>();
        if(state == 'TN')
        {       
            options.add(new SelectOption('CHE','Chennai'));
            options.add(new SelectOption('CBE','Coimbatore'));
        }
        else if(state == 'KL')
        {       
            options.add(new SelectOption('COA','Coachin'));
            options.add(new SelectOption('MVL','Mavelikara'));
        }
        else
        {
            options.add(new SelectOption('None','--- None ---'));
        }      
        return options;
    }       
}

Please copy and paste the above code and check the output.

Hope this helps you!
Best Regards,
Jyothsna

 
Bhargav krishna 1Bhargav krishna 1
Hi Tavva Sai Krishna,
can you give any example for custom it will be helpful for me.

Thanks in advance,
Regards,
Bhargav.
Shailendra Singh ParmarShailendra Singh Parmar
If you are on VF page then instead of VF rendering, JS would be good because in VF rendering you need to visit on server while in your case you are entering values and may not want to visit on server. You can have some java script in which you read some field and then dynamically update block css to display none or display based on what you want.
Here is display non example 
http://www.w3schools.com/jsref/prop_style_display.asp

Also jquery demo of show/hide
http://api.jquery.com/show/
Tavva Sai KrishnaTavva Sai Krishna
Hi Bhargav,

here is the below code of sample markup to understand this implemention.
<apex:page>
<apex:inputtext value="{!Tcol1}" id="Tcol1" onchange = "hide()"/>
<script>
function hide() {
    
    
    if(document.getElementById('{!$component.Tcol1}').value == 0.0 )
    {
        document.getElementById('{!$component.Tcol1}').style.display = "block";
    }
    else 
    {
        document.getElementById('{!$component.Tcol1}').style.display = "None";
    }
}
</script>
</apex:page>

If you need any help post your code here , i will modify and update your code.

Let me know if you face any issues/queries.

Thanks and Regards,
Sai Krishna Tavva.
Bhargav krishna 1Bhargav krishna 1
Thank You Tavva Sai Krishna.
Tavva Sai KrishnaTavva Sai Krishna
Hi Bhargav,

Please mark the answer as best answer as it may help to others.

Thanks and Regards,
Sai Krishna Tavva.