0

How can I re-render particular pageblocksection based on the onchange event from dropdownlist?

So here is what I have done:

   <apex:pageBlockSection title="Select Record Type" columns="1"> 
   <apex:selectList id="countries" value="{!RecordType}" size="1" required="true">
    <apex:selectOptions value="{!RecordTypes}"/>
     </apex:selectList>    
    </apex:pageBlockSection>

<apex:pageBlockSection rendered="{!RecordType.Name == 'employer'}" columns="1">
   <apex:outputText>Employer section</apex:outputText>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!RecordType.Name == 'employee'}" columns="1">
   <apex:outputText> Employee section</apex:outputText>
</apex:pageBlockSection>

My record type names are:

  • Employer
  • Employee
  • Which section you are getting while page load? Employer or Employee? – Vigneshwaran G Feb 24 '16 at 9:44
  • if your record type names are Employer and Employee, then the equality operator in the rendered= will fail because == is case sensitive in VF expressions. – cropredy Mar 1 '16 at 6:18
1

Try this:

<apex:pageBlockSection title="Select Record Type" columns="1"> 
    <apex:selectList id="countries" value="{!RecordType}" size="1" required="true">
        <apex:selectOptions value="{!RecordTypes}"/>
        <apex:actionSupport event="onchange" reRender="thePanels"/>
    </apex:selectList>    
</apex:pageBlockSection>

<apex:outputpanel layout="none" id="thePanels">
    <apex:pageBlockSection rendered="{!RecordType.Name == 'employer'}" columns="1">
        <apex:outputText>Employer section</apex:outputText>
    </apex:pageBlockSection>
    <apex:pageBlockSection rendered="{!RecordType.Name == 'employee'}" columns="1">
        <apex:outputText> Employee section</apex:outputText>
    </apex:pageBlockSection>
</apex:outputpanel>
  • does not do anything onchange have you tested? – Nick Kahn Feb 24 '16 at 1:25
  • 1
    This actually should work. – Andrii Muzychuk Oct 13 '17 at 15:50

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.