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
Sameer TyagiSameer Tyagi 

Want to hide controlling picklist from vf page only show dependend picklist on vf page.

HI 

I want to show dependent picklist on vf page and the value of controlling field I am setting on constructor of controller.
So my controlling picklist should be hidden and dependent picklist should be shown on vf page.
I have two picklist on object srobject__c
controller  organisation  picklist = abc,xyz
dependent picklist  : department  -- abc ={123,234.456}
xyz = 678,789,901



My code is :
public class sample{
public srobject__c newser {get;set}
public sample(){
}
newsr = new srobject__c();
            newsr.organization__c = 'abc';    //value of controlling picklist

}

===============page================
<apex:page  controller="sample">

<apex:inputField value="{!srvar.department__c}" />
</apex:page>
=================

please suggest me the code , your help would be appriciated.
Regards,
Sameer Tyagi

Best Answer chosen by Sameer Tyagi
Offshore Freelance ConsultantOffshore Freelance Consultant
Hi Sameer,

The following code should work.

In this example, I have Country__c and State__c as picklist vales State depending on Country.

-----------------
public class sample{

public Sample__c newser{get;set;}

public sample(){

    newser= new Sample__c();
   newser.Country__c= 'India';    //value of controlling picklist
}
}
-----------------

<apex:page  controller="sample" >
    <apex:form >
        <apex:inputField value="{!newser.Country__c}"  id="ParentPicklist" />
        <apex:outputLabel value="Please Select State :" />
        <apex:inputField value="{!newser.State__c}"  />

        <script>
            document.getElementById("{!$Component.ParentPicklist}").hidden=true;
        </script>

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

-----------------

Best Wishes,
JG

All Answers

Atul111Atul111
Sameer,

This should work,

If still you are facing this problem then get the data through meta data API only then you can do this.

Offshore Freelance ConsultantOffshore Freelance Consultant
Hi Sameer,

The following code should work.

In this example, I have Country__c and State__c as picklist vales State depending on Country.

-----------------
public class sample{

public Sample__c newser{get;set;}

public sample(){

    newser= new Sample__c();
   newser.Country__c= 'India';    //value of controlling picklist
}
}
-----------------

<apex:page  controller="sample" >
    <apex:form >
        <apex:inputField value="{!newser.Country__c}"  id="ParentPicklist" />
        <apex:outputLabel value="Please Select State :" />
        <apex:inputField value="{!newser.State__c}"  />

        <script>
            document.getElementById("{!$Component.ParentPicklist}").hidden=true;
        </script>

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

-----------------

Best Wishes,
JG
This was selected as the best answer
Sameer TyagiSameer Tyagi
Thanks JG

I have completed this requirement  by style attribute.

<apex:inputField value="{!newser.Country__c}"  style="display:none; />                      its working fine.


I used your suggestion code, Its also working fine.
However I was trying to  do it  through your  javascript code.
my actual page was

<apex:page  controller="sample" >
<apex:form >
        <script>
           document.getElementById("{!$Component.ParentPicklist}").hidden=true;
         </script>
        <apex:pageBlock id="thepage" mode="maindetail">
<apex:pageBlockTable value="{!newsr}" var="srvar" id="thetable" >
                    <apex:column headerValue="Action">
                      <apex:commandLink style="text-decoration:none; color:#015ba7" target="_Top" action="{!saveSRrecord}"                                          oncomplete="window.top.location='/{!custid}'; return false"  value="Save" status="bstatus">
                        
                       </apex:commandLink>
                     </apex:column>
                      <apex:column headerValue="Type">
                         <apex:inputField value="{!srvar.country__c}" id="ParentPicklist" >         //parent picklist still showing on page
                        <apex:inputField value="{!srvar.State__c}" />
                     </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
    </apex:form>
</apex:page>

and its not working
Can you please correct this code  ?

Regards,
Sameer
Offshore Freelance ConsultantOffshore Freelance Consultant
Hi Sameer,

Try putting the <script> code just above </apex:form>

since we are not putting the javascript code on any function and calling it, the code gets executed as the page gets loaded.

if we have script at the top, the control(picklist) is not loaded at that time.

Hope this helps!

Thanks for selecting my answer as best answer.

********************************
JG

Rudraprasad Shivananda 10Rudraprasad Shivananda 10
Can we hide multile level controlling fields..?? Say A controlls B, B Controlls C.. I am prepopulating A and B and want to hide them on page and display only C. User should select only C.
above solution is not working for multile level...!!! - any suggestions.. 

Thanks in advance..