0

I have a visualforce page that accepts inputs and creates an Opportunity...

In Standard Opportunity creation page layouts, there are many options for StageName, but in visualforce, I need to display fewer options to the user for this same field. How would I do this using server-code (not javascript)?

The closest approach that I have seen involves describing the field's picklist values and storing the subset that I care about into a selectlist and then putting that selectlist on the page similar to how its done here: UPDATED LINK: http://christopheralunlewis.blogspot.com/2010/10/creating-picklist-in-visualforce-page.html

Although this allowed me to define a selectList on the page with its options based on a subset of StageName, it was not a complete replacement for the Opportunity.StageName apex:inputfield because when I removed the Opportunity.StageName apex:inputfield the page failed to load because other fields depend on its existence on the page (standard picklist dependencies are defined in my org for Opportunity.StageName)

1 Answer 1

2

Unfortunately, as far as I know there is no way to do this with just the inputField element, since they allow almost no customization. However, you could create a controller variable to hold the user's choice and hide the inputField, then update it when they select a value. So:

<apex:outputPanel id="stageSection">
    <apex:selectList value="{!stageNameVar}" >
        <apex:selectOptions value="{!stageNames}" />
        <apex:actionSupport event="onchange" reRender="stageSection" action="{!updateStageName}"/>
    </apex:selectList>
    <apex:inputField value="{!Opportunity.StageName}" style="display:none" />
    <!--Dependent picklist fields -->
</apex:outputPanel>
1
  • i have not tested this but it makes sense. Thanks for the help, IllusiveBrian! Commented Dec 10, 2017 at 3:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .