+ Start a Discussion
maha123maha123 

Rendered problem with multi value picklist

Hello

I hope that someone can help me with my code

first, I have a vf page. In this page, there are sections that supposed to be hidden/shown according to the value of a multi-picklist. The standardController "Client Session Record" is a custome object

 

<apex:page standardController="Client_Session_Record__c">

  <apex:sectionHeader title="New client Session Record"
                      subtitle="{!Client_Session_Record__c.name}"/>
  <apex:form >
    
    <apex:pageBlock title="Client Session Record Edit" id="thePageBlock" mode="edit">
      <apex:pageMessages />
 
          <!--the buttons block  -->
          <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Cancel" action="{!cancel}"/>
          </apex:pageBlockButtons>
          <!--end of buttons block -->  

      <apex:actionRegion >
        <!--Section 1 -->   
        <apex:pageBlockSection title="Information" columns="2">
            

                  <apex:inputField value="{!Client_Session_Record__c.name}"/>
                  
                  <apex:pageBlockSection >
                      <apex:pageBlockSectionItem >

                      </apex:pageBlockSectionItem>

                      <!-- empty selectItem-->
                      <apex:pageBlockSectionItem />
                  </apex:pageBlockSection>
                  
                  
                  <apex:inputField value="{!Client_Session_Record__c.Date_of_visit__c}"/>
                  <apex:inputField value="{!Client_Session_Record__c.Advisor__c}"/>              
                  <apex:inputField value="{!Client_Session_Record__c.Client__c}"/>
                  <apex:inputField value="{!Client_Session_Record__c.X2nd_Advisor__c}"/>
                 
                  <!-- the condition -->
                  <apex:pageBlockSectionItem >              
                      <apex:outputLabel value="Session Type"/> 
                      <apex:outputPanel > 
                          <apex:inputField value="{!Client_Session_Record__c.Session_Type__c}">
                               <apex:actionSupport event="onchange"
                                            reRender="Section2, Section4"
                                            immediate="true"
                                            
                                            status="status"/>
                          </apex:inputField>
                          <apex:actionStatus startText="Updating the value..."
                                         id="status"/>
                      </apex:outputPanel> 
                  </apex:pageBlockSectionItem>
                  <!-- end of condition -->
                  <apex:inputField value="{!Client_Session_Record__c.Next_Review_Date__c}"/>
                  <apex:inputField value="{!Client_Session_Record__c.Location__c}"/>
                  
                          
        </apex:pageBlockSection>
        <!--Section 1 -->     
        
      </apex:actionRegion>
      

    <!--Section 2 -->  
          
      <apex:pageBlockSection title="Initial" id="Section2"
            columns="2" collapsible="true"  
            Rendered="{!if(Client_Session_Record__c.Session_Type__c=='Initial Assessment',true,false) }"  > 
                     
                     <apex:inputField value="{!Client_Session_Record__c.Recommended_AT__c}"
                         required="true" />  
                         
      </apex:pageBlockSection> 
       
    <!--Section 2 -->       
       
    </apex:pageBlock>
  </apex:form>
</apex:page>

 My problem is that , it didn't work!

 

Karthikeyan JayabalKarthikeyan Jayabal

Multi-select picklists can be used only with a limited set of formula functions & that's the reason your rendered formula didn't work. So, the only way is to set this Boolean value using a controller or extension class.

Below is the working sample code:

 

PAGE:

<apex:page standardController="Account" extensions="extension_multiSelectDemo">
    <apex:form >
        <apex:pageBlock id="pBlock" mode="edit">
            <apex:pageBlockButtons location="top">
                <apex:actionStatus id="rStatus" startText="Refreshing..."/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!account.Session_Type__c}">
                    <apex:actionSupport event="onchange" action="{!checkValue}" reRender="pBlock" status="rStatus"/>
                </apex:inputField>
                <apex:outputText rendered="{!isIA}">
                    Hey! I'm visible now :)
                </apex:outputText>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 EXTENSION:

public with sharing class extension_multiSelectDemo {
    Account account        { get; set; }
    public Boolean isIA    { get; set; }
    
    public extension_multiSelectDemo(ApexPages.StandardController controller) {
        account = (Account)controller.getRecord();
        isIA = false;
    }
    public PageReference checkValue() {
        if(account.Session_Type__c != null) {
            isIA = account.Session_Type__c.contains('Initial Assessment')?true:false;
        }else {
            isIA = false;
        }
        return null;
    }
}

 

 

 

swatKatswatKat

I think the CONTAINS function can help u . Here Location is the multiselect on the basis of which i am rendering the "nameSection"

 

<apex:form id="form1" >
        <apex:inputField value="{!account.Location__c}">
            <apex:actionSupport event="onchange" reRender="nameSection"/>
        </apex:inputField>
        <apex:outputPanel id="nameSection">
            <apex:outputField value="{!account.Name}" rendered="{!If(CONTAINS(account.Location__c, "Kolkata"),true,false)}"/>
        </apex:outputPanel>
    </apex:form>

 

maha123maha123

Thanks SwatKat, i tried this before and it didn't work

 

 i tried your ext class but still the sections are not showing when I want them to

Hope you can tell me more or what I'm missing

Karthikeyan JayabalKarthikeyan Jayabal
maha, please post your modified code & I can suggest better...
maha123maha123

here is my vf page

<apex:page standardController="Client_Session_Record__c" extensions="extension_multiSelectDemo">

  <apex:sectionHeader title="New client Session Record"
                      subtitle="{!Client_Session_Record__c.name}"/>
  <apex:form >
    
    <apex:pageBlock title="Client Session Record Edit" id="thePageBlock" mode="edit">
      <apex:pageMessages />
 
          <!--the buttons block  -->
          <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Cancel" action="{!cancel}"/>
          </apex:pageBlockButtons>
          <!--end of buttons block -->  

      <apex:actionRegion >
        <!--Section 1 -->   
        <apex:pageBlockSection title="Information" columns="2">
            

                  <apex:inputField value="{!Client_Session_Record__c.name}"/>
                  
                  <apex:pageBlockSection >
                      <apex:pageBlockSectionItem >

                      </apex:pageBlockSectionItem>

                      <!-- empty selectItem-->
                      <apex:pageBlockSectionItem />
                  </apex:pageBlockSection>
                  
                  
                  <apex:inputField value="{!Client_Session_Record__c.Date_of_visit__c}"/>                   
                  <apex:inputField value="{!Client_Session_Record__c.Advisor__c}"/>              
                  <apex:inputField value="{!Client_Session_Record__c.Client__c}"/>
                  <apex:inputField value="{!Client_Session_Record__c.X2nd_Advisor__c}"/>
                 
                  <!-- the condition -->
                  <apex:pageBlockSectionItem >              
                      <apex:outputLabel value="Session Type"/> 
                      <apex:outputPanel > 
                          <apex:inputField value="{!Client_Session_Record__c.Session_Type__c}">
                               <apex:actionSupport event="onchange"
                                            reRender="Section2"
                                            immediate="true"
                                            
                                            status="status"/>
                          </apex:inputField>
                          <apex:actionStatus startText="Updating the value..."
                                         id="status"/>
                      </apex:outputPanel> 
                  </apex:pageBlockSectionItem>
                  <!-- end of condition -->
                  <apex:inputField value="{!Client_Session_Record__c.Next_Review_Date__c}"/>
                  <apex:inputField value="{!Client_Session_Record__c.Location__c}"/>
                  
                          
        </apex:pageBlockSection>
        <!--Section 1 -->     
        
      </apex:actionRegion>
      

    <!--Section 2 -->  
          
      <apex:pageBlockSection title="Observation" id="Section2"
            columns="2" collapsible="true" >
            rendered="{!isIA}">            
                      <apex:inputField value="{!Client_Session_Record__c.Background_Information__c}"
                         required="true" />
                      
                         
      </apex:pageBlockSection> 
       
    <!--Section 2 --> 
    
    <!--Section 
      <apex:pageBlockSection title="Provision" id="Section3"
            columns="2" collapsible="true"  />
      </apex:pageBlockSection>         
    <!--Section 3 -->  

    <!--Section 4 --> 
      <apex:pageBlockSection title="Training" id="Section4"
            columns="2" collapsible="true"  
            Rendered="{if(CONTAINS(!Client_Session_Record__c.Session_Type__c,'Training'),true,false)}"  > 
      </apex:pageBlockSection>        
    <!--Section 4 -->  
    
    <!--Section 5 -->  
    <!--Section 6 -->
    <!--Section 7 -->    
          
    </apex:pageBlock>
  </apex:form>
</apex:page>

 and the class

public with sharing class extension_multiSelectDemo {
    
    Client_Session_Record__c clientSession { get; set; }
    public Boolean isIA    { get; set; }
    
    public extension_multiSelectDemo (ApexPages.StandardController controller) {
        clientSession = (Client_Session_Record__c)controller.getRecord();
        isIA = false;
    }
    
     public PageReference checkValue() {
        if(clientSession.Session_Type__c != null) {
            isIA = clientSession.Session_Type__c.contains('Initial Assessment')?true:false;
        }else {
            isIA = false;
        }
        return null;
    }

}

 

Karthikeyan JayabalKarthikeyan Jayabal

You have missed to call the checkValue action method whenever the SessionType field changes.

So, just add action={!checkValue} to the sessiontype inputfield, as shown below & it'll work as you expect.

 

<!-- the condition -->
                  <apex:pageBlockSectionItem >              
                      <apex:outputLabel value="Session Type"/> 
                      <apex:outputPanel > 
                          <apex:inputField value="{!Client_Session_Record__c.Session_Type__c}">
                               <apex:actionSupport event="onchange" action="{!checkValue}" 
                                            reRender="Section2"
                                            immediate="true"
                                            
                                            status="status"/>
                          </apex:inputField>
                          <apex:actionStatus startText="Updating the value..."
                                         id="status"/>
                      </apex:outputPanel> 
                  </apex:pageBlockSectionItem>

 

Karthikeyan JayabalKarthikeyan Jayabal

Also, just noted one more mistake:

Replace the Client_Session_Record__c variable ONLY in your VF page with clientSession

maha123maha123

I really appreciate your help for now that I got a result, thanks to u.

 

But still works funny! :(

It only works after saving the record and doesn't hide/show what I want when I do  select from the picklist.

also I had to reselect "initial assessment" from the picklist with the saved records to show the hidden fields

 even after I save it, i still need to reselect my choices next time i try to edit

 

 

Karthikeyan JayabalKarthikeyan Jayabal

I guess, only other culprit is the actionRegion part.

Currently actionRegion encloses the whole section1, so change it just enclose the inputfield:Session_Type__c.

This should enable partial refresh without saving the record.

maha123maha123

I changed the actionRegion to encloses only the "Session_Type__c" field.
yet still it doesn't work properly!

1. If I create any new record and try to choose "Initial Assessment", nothing happens as if the event=onchange doesnot work!
2. If I try to modify a record, and "Initial Assessment" is already selected, the rendered fields still doesn't show until I reselect "Initial Assessment"; event=onchange must be forced although it's already in selected choices

Thanks again

Baird_SBaird_S
Simpler solution: 
rendered="{!if(contains(object.multipicklistfield__c,'value'),false,true)}" 

In the case above that would be: 
rendered="{!If(CONTAINS(account.Location__c, 'Kolkata'),true,false)}":

SwatKat almost had it above.  His suggestion was: !if(contains(SObject.multipicklistfield__c,"value"),false,true)  The problem was the quotation mark instead of apostrophe. His solution works fine outside of a visualforce page, but in the Visualforce notation the quotation marks around the value cause a format error because Visualforce thinks that they are the end of the rendered statement. 



 
Frederic KrebsFrederic Krebs
Thanks to Baird_S : your solution works for me
BUT border effects are
- i need to add my outputField into an outputPanel
- i need to do a trick to show the Label + having the good format for the label <- a real nightmare !

Here is the code i am using, which is aroung 98% of what i want (tehre is a little left margin)
<apex:actionRegion >
<apex:pageBlockSection
<apex:pageBlockSectionItem >
    <apex:outputlabel value="Stage"/>
        <apex:outputpanel >
            <apex:inputfield value="{!opportunity.stageName}">
                <apex:actionSupport event="onchange"   rerender="thePageBlock"  status="status"/>
            </apex:inputfield>
            <apex:actionStatus startText="applying value..." id="status"/>
        </apex:outputpanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion >

........

<apex:pageBlockSection
<apex:inputfield value="{!opportunity.Loss_Reasons__c}" >
    <apex:actionSupport event="onchange"   rerender="panelMissingFeature" />
</apex:inputfield>

<apex:outputPanel id="panelMissingFeature" >
    <apex:pageBlockSection columns="1" id="inputMissingFeature"  rendered="{!IF(CONTAINS(opportunity.Loss_Reasons__c,'Missing Feature'),true,false)}">
        <apex:inputField value="{!opportunity.Missing_Features__c}" />
    </apex:pageBlockSection >
</apex:outputPanel>   
</apex:pageBlockSection