[SalesForce] Is it possible to re-render select options for a SelectList based on selected options for other SelectList controls on the same page

I am trying to figure out how I would dynamically update the SelectOptions for multiple SelectLists on the same visualforce page.

I have a page where the user selects contacts that are associated with a previously selected account (step one of a wizard control). I have 5 SelectList controls on this page.

What I would like to have happen is when the user selects a contact in the first selectlist control, I update the selectoptions for the other controls to remove that contact as a select option (so the user can't select the same contact in multiple selectlists on the page).

I've been playing with the apex:actionFunction and the reRender attribute, but I can't seem to get this working.

Can anyone show me if it is possible to do what I've described above? Or provide an example of how you would accomplish this (assuming it's possible)?

Thank you!

Best Answer

You can accomplish this by adding an ActionSupport to each of the SelectOptions

<apex:pageBlockSection >
     <apex:actionRegion >
    <apex:selectList value="{!conid}" size="1" >
      <apex:selectOptions value="{!Cons}" />
      <apex:actionSupport action="{!updateCONLIST}" event="onchange" reRender="pBlock" />
     </apex:selectList>
    <apex:selectList value="{!conid2}" size="1" id="pBlock" >
        <apex:selectOptions value="{!Cons2}" />
    <apex:actionSupport action="{!updateCONLIST}" event="onchange" reRender="rBlock" />
        </apex:selectList>
    <apex:selectList value="{!conid3}" size="1" id="rBlock" >
        <apex:selectOptions value="{!Cons3}" />
    </apex:selectList>
         </apex:actionRegion>
</apex:pageBlockSection>

Depending on how long your SOQL might take to run, you could also include an ActionStatus to show a "please wait" type of message each time it is rerendering (and updating your dependent lists).

Related Topic