3

I have a VF page where the user can select the RecordType before seeing all the fields for the selected record type on my custom object Request_For_System_Change.

Here is the VF Code:

    <apex:outputPanel id="RecordTypeBlank">
    <div Id="RecordTypeQuestion">
        <div  class="headerBlue" style="font-weight: 500;">
            Please select the record type before continuing
        </div>
        <table border="" style="width:100%;" >
            <tr>    
               <td valign="middle" align="right" style="width:21%; padding-right: 3px;" >
                    <apex:outputLabel value="Type of Change:"/>                                
                </td>
                <td valign="middle" align="left" style="width:79%; padding-left: 4px;" >
                    <apex:selectList value="{!recordType}" size="1">
                        <apex:actionSupport event="onchange" rerender="PageFields, RecordTypeBlank" status="vfStatus"/>
                        <apex:selectOptions value="{!RecordTypes}"/>
                    </apex:selectList>                      
                </td>
            </tr>
        </table>    
    </div>
</apex:outputPanel>            

<apex:outputpanel id="PageFields" >

    <!-- Fields for System Change Request -->
    <apex:outputpanel rendered="{!recordType == 'System Change Request'}"> 
        <div class="blueBorder WidthAuto"
..... cut ...

So, when the user selects a recordType, the onchange event fires (the first time) and the <outputPanel PageFields is re-rendered with the outputPanel to be shown determined by the value of the variable recordType in the controller, which is set as the value for the selectList control.

This all works fine the first time, I can choose any of the 3 recordTypes and the fields for that recordType are correctly displayed.

Unfortunately, once a record type is chosen, if I then change the recordType in the selectList, nothing happens...

so how can I change this so that every time the record type is changed, the PageFields outputPanel will be re-rendered, showing the correct fields?

To me it looks like the onchange event is only firing the first time...

  • 1
    Why you are re-render the RecordTypeBlank panel? Apart from that your code looks good. Additionally you can try to wrap your selectList with an <apex:actionRegion>. – Sergej Utko Jan 20 '16 at 10:00
  • 1
    I'm going to guess that you have {!recordType} as a merge field somewhere else on the page that is also transmitted to the controller on the actionSupport. It contains the old value and wipes out the new value so when rerendering occurs, nothing has changed. Try wrapping the selectList in an actionRegion. – cropredy Jan 20 '16 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.