5

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!

  • 1
    You shouldn't need action function. Have you tried adding apex:actionSupport to the selectOption control? You might also help us by putting an annotated version of the code you are using so we can get an idea of what you've tried. Thanks! – pchittum Dec 17 '13 at 16:09
7

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).

|improve this answer|||||

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.