0

I'm having problems getting a list inside of a tag to render as a dropdown picklist. I don't want the picklist to appear as a multi-select picklist, with all possible values displayed as a list, but instead as a standard HTML dropdown where you only see the first value and then click the list to see the rest. Any pointers as to what I'm doing wrong here?

nb this is a simplified version of the controller and page. Lots of extra code omitted that has nothing to do with the problem at hand.

rendered picklist

controller code:

public class ots{



 public Id gId = ApexPages.currentPage().getParameters().get('gId');
//system.debug('gId is: '+gId);

 Opportunity o = [SELECT id, Competitor_s__c from Opportunity where Id =:gId];
 public List<SelectOption> comps {get;set;} 
 public List<OpportunityLineItem> olist {get;set;}
 String[] tempstring {get;set;}


public List<SelectOption> getfixedVals(){
    List<SelectOption> stomps = new List<SelectOption>();
    stomps.add(new SelectOption('Test 1','Test 1'));
    stomps.add(new SelectOption('Test 2','Test 2'));
    stomps.add(new SelectOption('Test 3','Test 3'));

    return stomps;

}

page code:

<apex:page controller="ots">
<apex:form>
<apex:outputPanel>
  <apex:selectList id="dropdown"> 
  <apex:selectOptions value="{!fixedVals}" rendered="true">
</apex:selectOptions>
  </apex:selectList>
 </apex:outputPanel>
</apex:form>
</apex:page>
1
  • 1
    Can you try adding size="1" attribute in <apex:selectList> .Like <apex:selectList id="dropdown" size="1"> – Hemant Jain Mar 22 '18 at 10:24
2

For apex:selectList, set the attribute multiselect as false and size as 1.

<apex:selectList id="dropdown" multiselect="false" size="1"> 
    <apex:selectOptions value="{!fixedVals}" rendered="true">
</apex:selectOptions>
1
  • Thanks for that pointer Rahul, exactly what I was looking for ! – akarnid Mar 22 '18 at 10:41
0

Check out the page of https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm. You can set the size as well as the multiselect attribute

1
  • Damn - too late :) – utm Mar 22 '18 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.