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
Brandon Bridges 16Brandon Bridges 16 

With good reason, How do I show white space (blank) instead of --none-- in a visualforce case picklist?

With good reason, How do I show white space (blank) instead of --none-- in a visualforce case picklist? 

​I have about 10 picklist fields. None are required and I want the ones that have no value to be blank white space instead of "--none--". 

The reason for this is to keep my UI looking clean and readable.
Having 10 fields with a label and "--none--" beside each of them is very cumbersome. I'd much rather they just show blank.
Best Answer chosen by Brandon Bridges 16
SijuSiju
Instead of using <apex:inputField ... use the <apex:selectList . and in the controller , get the picklist list values of each field and add it individually using  
          List<SelectOption> options = new List<SelectOption>();
          options.add(new SelectOption('picklistvalue1','picklistvalue1'));
Create a common method to get the picklist vale and pass the fieldname as a parameter. PFB the sample code for

 
public static List<String> getPicklistValues(String Field_name){ 
 String ObjectApi_name='Case'; 
  List<String> lstPickvals=new List<String>();
  Schema.SObjectType targetType = Schema.getGlobalDescribe().get(ObjectApi_name);//From the Object Api name retrieving the SObject
    Sobject Object_name = targetType.newSObject();
  Schema.sObjectType sobject_type = Object_name.getSObjectType(); //grab the sobject that was passed
    Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe(); //describe the sobject
    Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap(); //get a map of fields for the passed sobject
    List<Schema.PicklistEntry> pick_list_values = field_map.get(Field_name).getDescribe().getPickListValues(); //grab the list of picklist values for the passed field on the sobject
    for (Schema.PicklistEntry a : pick_list_values) { //for all values in the picklist list
      lstPickvals.add(a.getValue());//add the value  to our final list
   }
  
  return lstPickvals;
}

 

All Answers

Sure@DreamSure@Dream
Hi Brandon,

Unforunately, there is not a straight forward way. You can try the below approach.

You need to create your own picklists:
1. Create List<SelectOption> in controller. One for each of the picklist.
2. Add the picklist values to the list variables. Refer:
http://salesforce.stackexchange.com/questions/4992/how-to-get-a-picklist-all-values-in-apex-controller
3. Use the list variables in visualforce page:
<apex:selectList value="{!selectedValue}" size="1" label="{!$ObjectType.sObjectAPIName.fields.fieldAPIName.Label}">
<apex:selctOptions value="{!List_Name}"/>
</apex:selectList>
Mark this as the solution, if it solves your problem.

Thanks
 
SijuSiju
Instead of using <apex:inputField ... use the <apex:selectList . and in the controller , get the picklist list values of each field and add it individually using  
          List<SelectOption> options = new List<SelectOption>();
          options.add(new SelectOption('picklistvalue1','picklistvalue1'));
Create a common method to get the picklist vale and pass the fieldname as a parameter. PFB the sample code for

 
public static List<String> getPicklistValues(String Field_name){ 
 String ObjectApi_name='Case'; 
  List<String> lstPickvals=new List<String>();
  Schema.SObjectType targetType = Schema.getGlobalDescribe().get(ObjectApi_name);//From the Object Api name retrieving the SObject
    Sobject Object_name = targetType.newSObject();
  Schema.sObjectType sobject_type = Object_name.getSObjectType(); //grab the sobject that was passed
    Schema.DescribeSObjectResult sobject_describe = sobject_type.getDescribe(); //describe the sobject
    Map<String, Schema.SObjectField> field_map = sobject_describe.fields.getMap(); //get a map of fields for the passed sobject
    List<Schema.PicklistEntry> pick_list_values = field_map.get(Field_name).getDescribe().getPickListValues(); //grab the list of picklist values for the passed field on the sobject
    for (Schema.PicklistEntry a : pick_list_values) { //for all values in the picklist list
      lstPickvals.add(a.getValue());//add the value  to our final list
   }
  
  return lstPickvals;
}

 
This was selected as the best answer