function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShikibuShikibu 

can't attach an ajax event to a multi-picklist?

I am having trouble attaching an ajax event to a multi-picklist.

I want to display the text field Case.Other_Categories__c if and only if if "Other" is selected in the multi-picklist Case.Categories__c.

public Boolean displayOther { get { return theCase.Categories__c != null && theCase.Categories__c.contains('Other'); } }

 

 

 

<apex:pageBlockSection> <apex:actionregion immediate="true"> <apex:inputField value="{!Case.Categories__c}"> <apex:actionSupport event="onblur" rerender="other_categories" status="updating_other_status"/> </apex:inputField> </apex:actionregion> <apex:inputField value="{!Case.Other_Categories__c}" rendered="{!displayOther}" id="other_categories"/> <apex:actionStatus startText="updating..." id="updating_other_status" /> </apex:pageBlockSection>

 

I've tried onclick, onchange, ondblclick, and onblur events, but I never see the actionstatus displayed, and watching in firebug I never see an ajax submit.

 

 

Is there a trick to this?
bob_buzzardbob_buzzard

You haven't provided an action attribute for your actionSupport component.  According to the docs, this will simply cause a page refresh, which may be why you aren't seeing an Ajax request.

 

Also, you've specified immediate="true".  This means that the values you have entered are discarded rather than used to update the bound properties from your controller.  Remove this attribute (same as setting it to false) and you should see the second input field displayed when you select the appropriate item from the multi-select picklist.

 

 

Rajesh ShahRajesh Shah
Yes, you will have to add the action attribute and remove the immediate = 'true' part. Also, you might face another problem. When we try to rerender a component  which has a rendered attribute, it doesnt works. So might want to put the next inputField inside pageBlockSectionItem and rerender the sectionItem.
ShikibuShikibu

After more experimenting, I can demonstrate that no action is needed, and that "immediate=true" is not the problem.


The following is a complete example of a VF page that exhibits the behavior I want. "immediate=true" is necessary in order to have the bound variables within the actionregion posted/submitted without causing validation of other fields on the page (which would fail and produce big red error messages if user has not yet completely entered all data).

 

No action is required, because all I want is to rerender a part of the page.


This page doesn't depend upon any apex code; is uses no controller. When the user chooses "New" for status, a post occurs, and the "Other" field is displayed. When the user then chooses any other status, the Other field disappears. The actionstatus makes clear that this is happening.

 

However, If I replace Case.Status and CONTAINS(Case.Status, "New" ) with Case.Categories__c and CONTAINS(Case.Categories__c, 'Other'), then no rerendering occurs.

 

I suspect that this is a bug in the way events are implemented for multipicklists.

 

 

 

 

<apex:page standardController="Case">

<apex:form>

<apex:pageBlock id="wholePage">

<apex:pageBlockSection id="rerender_target">
<apex:pageBlockSectionItem>
<apex:outputLabel value="Case Status" for="categories"/>
<apex:actionregion immediate="true">
<apex:inputField value="{!Case.Status}"
required="true">
<apex:actionSupport event="onchange"
rerender="rerender_target"
status="updating_other_status"/>
</apex:inputField>
</apex:actionregion>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem>
<apex:outputPanel rendered="{!CONTAINS(Case.Status,'New')}">
<apex:outputLabel value="Other Categories" for="other_categories"/>
<apex:inputField value="{!Case.Other_Case_Categories__c}"
id="other_categories"/>
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:actionStatus startText="updating..." id="updating_other_status" />

</apex:pageBlockSection>


</apex:pageBlock>
</apex:form>

</apex:page>

 

 

 

 

Message Edited by Shikibu on 10-28-2009 12:41 PM
bob_buzzardbob_buzzard

The CONTAINS function only works with picklists.

 

With multi-picklists you will need to use INCLUDES 

ShikibuShikibu
"Error: Function INCLUDES may not be used in this type of formula"

 

 

<apex:outputPanel rendered="{!INCLUDES(Case.Case_Categories__c,'Other')}">

 

 However, I don't think the formula is the problem, because this also never produces a rerender:

 

 

<apex:outputPanel rendered="{!LEN(Case.Case_Categories__c)!=0}">

 

 

 

I think, instead, that multipicklists generate compound html (the two column thingy is not a feature of any html element I am aware of), and that salesforce has not implemented events correctly for the generated code.

 

bob_buzzardbob_buzzard
You may well be right - I must admit, I never liked the look of the multi-picklist stuff, so I've written a custom component that uses two selectList components. 
shippushippu

Hi bob_buzzard,