+ Start a Discussion
kabkab 

How to Hide a Specific Picklist Value in a Visual Force Page?

I am wondering is there a way I can hide a specific value in a visualforce page using either controller or in Visualforce page.

 

Suppose I have original Picklist Values in setup :

A- 123

B-234

C-345

 

I want to Display only 2 values on a Visual force page.Like

 B-234

C-345

How can I acheive this?

 

Please put some code if it is possible.

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

You can hide specific picklist value through controller and below is the sample code:

 

                                ------------- Controller Code ---------------

                                Public string propPickValSelected { get; set; }

                                public List<SelectOption> getPickLstValue()

                                {

                                                List<SelectOption> options = new List<SelectOption>();

                                                Schema.DescribeFieldResult fieldResult = Account.PickLst__c.getDescribe();

                                                List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

                                                for(Schema.PicklistEntry f : ple)

                                                {

                                                                if(f.getValue() != 'A- 123')

                                                                {

                                                                                options.add(new SelectOption(f.getLabel(), f.getValue()));

                                                                }

                                                } 

                                    return options;           

                                }

 

                                --------------- VF Page Code -----------------

                                <apex:selectList title="PickList1" size="1" value="{!propPickValSelected}" styleClass="form-select">

                                                <apex:selectOptions value="{!PickLstValue}"/>

                                </apex:selectList>

All Answers

sham_1sham_1

You can try using describe methods to get avaliable values for a picklist and use an apex:select tag to display the ones you require.

Pradeep_NavatarPradeep_Navatar

You can hide specific picklist value through controller and below is the sample code:

 

                                ------------- Controller Code ---------------

                                Public string propPickValSelected { get; set; }

                                public List<SelectOption> getPickLstValue()

                                {

                                                List<SelectOption> options = new List<SelectOption>();

                                                Schema.DescribeFieldResult fieldResult = Account.PickLst__c.getDescribe();

                                                List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

                                                for(Schema.PicklistEntry f : ple)

                                                {

                                                                if(f.getValue() != 'A- 123')

                                                                {

                                                                                options.add(new SelectOption(f.getLabel(), f.getValue()));

                                                                }

                                                } 

                                    return options;           

                                }

 

                                --------------- VF Page Code -----------------

                                <apex:selectList title="PickList1" size="1" value="{!propPickValSelected}" styleClass="form-select">

                                                <apex:selectOptions value="{!PickLstValue}"/>

                                </apex:selectList>

This was selected as the best answer
kabkab

 

This will work but in my case I have dependent picklist and for that I have used following and it worked for me.

 <script>

var list=document.getEleementbyId('List1');

list.remove(index);

 

</script>