I have a Visualforce page that uses actionRegion and actionSupport tags to render a section of the page based upon the value selected in a picklist field. That all works fine. However, some of the fields in the section that is rendered are conditionally required. Yet, when the value of the picklist field is changed so that those field should no longer be required, they are still preventing the rerender stating that the fields are required. Am I doing something wrong here?

VF Page:

<apex:page standardController="Case">

<style type="text/css">
    .widthClass { width: 75%; }

<apex:form >
    <apex:sectionHeader subtitle="New Case" title="Case Edit"/>
        <apex:pageBlock mode="edit" title="Case Edit">
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!Save}"/>&nbsp;&nbsp;<apex:commandButton value="Cancel" action="{!Cancel}"/>

        <apex:outputPanel Id="Reason">
            <apex:pageblockSection title="Case Information" columns="2">
                <apex:inputField value="{!Case.OwnerId}"/>
                <apex:inputField value="{!Case.RecordTypeId}"/>
                    <apex:inputField value="{!Case.Case_Reason__c}">
                        <apex:actionSupport event="onchange" rerender="Reason"/>
                <apex:inputField value="{!Case.Origin}"/>
                <apex:inputField value="{!Case.AccountId}"/>
                <apex:inputField value="{!Case.ContactId}"/>
                <apex:inputField value="{!Case.Status}"/>

        <apex:outputPanel id="screenshot">
        <apex:outputPanel rendered="{!IF(Case.Case_Reason__c = 'Screenshot',true,false)}">
            <apex:pageblockSection title="Screenshot Information" columns="2">
                <apex:inputField value="{!Case.Use_Case__c}" required="{!IF(Case.Case_Reason__c = 'Screenshot',true,false)}"/>
                <apex:inputField value="{!Case.Campaign_ID__c}" required="{!IF(Case.Case_Reason__c = 'Screenshot',true,false)}"/>
                <apex:inputField value="{!Case.Campaign_Name__c}"/>
                <apex:inputField value="{!Case.Screenshot_Date_Range_Start__c}"/>
                <apex:inputField value="{!Case.Screenshot_Date_Range_End__c}"/>
                <apex:inputField value="{!Case.Screenshot_Format__c}" required="{!IF(Case.Case_Reason__c = 'Screenshot',true,false)}"/>



  • Any reason you don't just make those fields required all the time? They'll only exist on the page when the case reason is screenshot, so only be required then... I think. – Nick Cook Jun 29 '16 at 14:44

Try specifying immediate="true" on your actionSupport tag. Without that attribute, the visualforce page will try to submit the form to the server, which will trigger the page validation. Specifying this tag will prevent the form submission, and rerender the section.

From the actionSupport documentation:

A Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.

  • Thanks. When I add that it does get rid of the error messages, but now it does not rerender my "screenshot" section, meaning it should disappear from the layout based upon my rendered condition. Any idea why? – J. Neilan Jun 29 '16 at 14:52
  • The server and the page have two different data sets- when you call the rerender, it's still using the data from the server, since the server is the one generating the page html. Without submitting the first section to the server, or adding an action to your actionSupport tag, I dont think youll be able to pass this value along to the rendered tag. – battery.cord Jun 29 '16 at 14:56
  • If you can add a controller extension, you can add a value for the cases field value, and update it when you first load the page, as well as through a action along with the rerender. This should get the expected behavior, however, it does require you to write a controller for the page. – battery.cord Jun 29 '16 at 14:57
  • Thanks. Was hoping to avoid a controller, but looks like that might be the best bet. – J. Neilan Jun 29 '16 at 15:48

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.