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
Maria Alexandra AndricaMaria Alexandra Andrica 

hide picklist value

Hi ,

I want not to display in the Visualforce all the picklist values available and tried to hide them using below code but it is not working. Can you please help?

     <apex:inputField required="true" value="{!pageCtrl.newCont.Status__c}" id="st" />
                                     <script type="text/javascript">
                                     (function(){
                                         var inputStatus=document.querySelectorAll('[id$="st"]');
                                         for (var i=0; i<inputStatus.length; i++){
                                             if (inputStatus.options[i].value == 'Unqualified' )
                                                 inputStatus.remove(i);
                                         }
                                     }
                                      </script>        
Waqar Hussain SFWaqar Hussain SF
Hi Maria,

Try below code
 
<apex:inputField required="true" value="{!pageCtrl.newCont.Status__c}" id="st" />
 <script type="text/javascript">
 (function(){
	 var inputStatus=document.querySelectorAll('[id$="st"]');
	 for (var i=0; i<inputStatus.length; i++){
		 if (inputStatus[i].value == 'Unqualified' )
			 inputStatus.remove(i);
	 }
 }
  </script>

 
Maria Alexandra AndricaMaria Alexandra Andrica
Hi Waqar,

thank you for the help, but it is stll not working. Am I missing something?
Waqar Hussain SFWaqar Hussain SF
Hi Maria, I just tried the below code which worked fine for me.
 
<apex:page standardController="Opportunity" id="pg">
<script>

window.onload = function() {
  hidePicklist();
};

 function hidePicklist(){
     var select=document.getElementById('pg:frm:st');

    for (i=0;i<select.length;  i++) {
       if (select.options[i].value=='Prospecting') {
         select.remove(i);
       }
    }
 }
  </script>
 
<apex:form id="frm">
<apex:inputField required="true" value="{!Opportunity.StageName}" id="st" />
  
</apex:form>  
</apex:page>

 
Maria Alexandra AndricaMaria Alexandra Andrica
I need to inegrate it in a visualforce component. How should this line be adapted for VFC?
var select=document.getElementById('pg:frm:st'); th
Waqar Hussain SFWaqar Hussain SF
var select=document.getElementById('​{!$Component.st}');


 
Maria Alexandra AndricaMaria Alexandra Andrica
I tried in this way, but still is not working. Do you see something wrong?

<apex:component allowDML="true">
    <apex:attribute name="pageCtrl" type="ExtManageMinutes" description="the root page controller reference" />
    <apex:attribute name="rerenderList" type="String" description="To rerender the chatter" />
    <script>
    window.onload = function() {
        hidePicklist();
    };   
    function hidePicklist(){
        var select=document.getElementById('{!$Component.contDetailSection.block1.block2.st}');
        
        for (i=0;i<select.length;  i++) {
            if (select.options[i].value=='Unqualified') {
                select.remove(i);
            }
        }
    }
    <script>
        <apex:form id="contDetailSection">
            <input type="hidden" id="savePopUpError" value="{!pageCtrl.pageConf.isPopUpError}"/>
            <apex:actionFunction name="saveCont" action="{!pageCtrl.saveNewContact}" rerender="contactListId,contDetailSection" oncomplete="attendees.init();attendees.hideContDetail();openLinkType();deleteEmptyTd();" />
            <apex:pageBlock title="New Contact" id="block1">
                <apex:pageMessages id="pageMsg"/>               
                <input type="button" class="btn" value="Save" onclick="attendees.saveContact();"/>
                <input type="button" class="btn" value="Cancel" onclick="attendees.closeNewContact();"/>
                <apex:pageBlockSection showHeader="false" columns="1" id="block2">     
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </div>
</apex:component>