1

I have an object named Expenses__c. This object has a field named Expense_Type__c, which contains these values: Customer and Employee.

Here's the requirement: When I select Customer from Expense_Type__c picklist field, a lookup field (named Customer__c) for Customer object must be displayed. But when I select Employee, lookup field (named Employee__c) for Employee object must appear. These lookup fields must only be displayed upon the selection of their controlling picklist value.

I've already used actionSupport, and actually it's working. The only problem is that it works only in Customer, not in Employee. How can I solve this?

By the way, here's my code:

Vf page : ExpensePage

<apex:page standardController="Expenses__c">
  <apex:form>
    <apex:pageblock>
      <apex:selectList value="{!Expenses__c.Type__c}" size="1">  
        <apex:actionSupport event="onchange" reRender="lookup1"/> 
        <apex:actionSupport event="onchange" reRender="lookup2"/>              
        <apex:selectOption itemValue="--None--" itemLabel="--None--"/> 
        <apex:selectOption itemValue="Customer" itemLabel="Customer"/> 
        <apex:selectOption itemValue="Employee" itemLabel="Employee"/> 
      </apex:selectList> 

      <apex:outputPanel id="lookup1">
        <apex:inputField value="{!Expenses__c.Customer__c}" rendered="{!Expenses__c.Type__c='Customer'}"/>
      </apex:outputPanel>

      <apex:outputPanel id="lookup2">
        <apex:inputField value="{!Expenses__c.Employee__c}" rendered="{!Expenses__c.Type__c='Employee'}"/>
      </apex:outputPanel>
    </apex:pageblock>
  </apex:form>  
</apex:page>
2
  • Consolidate your two actionSupport tags into one, you can use a comma separated list.
    – Adrian Larson
    Jun 11, 2016 at 15:20
  • Very simple than I've imagined! It's working, thanks @AdrianLarson
    – Gaynerys
    Jun 11, 2016 at 15:42

1 Answer 1

1

Consolidate your two actionSupport tags into one, you can use a comma separated list.

<apex:actionSupport event="onchange" reRender="lookup1,lookup1" /> 

You must log in to answer this question.

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