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
kory108kory108 

actionSupport rerender not working on inputField

Hello,

The below code should show the Marketing_Request__c.Other_Channel__c inputField when a Marketing_Request__c.Channel__c of "Other" is selected, however it appears the page is not rerendering correctly. When a choice of "Other" is selected, the Other Channel inputField is never diplayed.

Any assistance resolving this is much appreciated.
<apex:page standardController="Marketing_Request__c">
    <apex:sectionHeader title="Edit Marketing Request" subtitle="{!Marketing_Request__c.Name}"/>
    <apex:form>
        <apex:pageBlock title="Edit Marketing Request" id="thePageBlock" mode="edit">
            
            <apex:pageMessages />
            
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection title="Branding and Channel" columns="1">
                <apex:inputField value="{!Marketing_Request__c.Branding_Type__c}" required="true"/>
                <apex:inputField value="{!Marketing_Request__c.Channel__c}" required="true">
                    <apex:actionSupport event="onchange" rerender="thePageBlock" immediate="true" status="channelStatus"/>
                </apex:inputField>
                <apex:actionStatus startText="applying change..." id="channelStatus"/>
                <apex:inputField value="{!Marketing_Request__c.Other_Channel__c}" required="true" rendered="{!Marketing_Request__c.Channel__c == 'Other'}"/>
            </apex:pageBlockSection>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>
User-added image
 
Best Answer chosen by kory108
Pramodh KumarPramodh Kumar
Hey Kory


when you try to rerender the pageblock entire block will be refreshed. Instead you only refresh part of the block.


Please try this code and let me know if you have any problems
 
<apex:page standardController="Marketing_Request__c">
    <apex:sectionHeader title="Edit Marketing Request" subtitle="{!Marketing_Request__c.Name}"/>
    <apex:form>
        <apex:pageBlock title="Edit Marketing Request" id="thePageBlock" mode="edit">
            
            <apex:pageMessages />
            
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection title="Branding and Channel" columns="1" id="pageBlockSection">
                <apex:inputField value="{!Marketing_Request__c.Branding_Type__c}" required="true"/>
                <apex:inputField value="{!Marketing_Request__c.Channel__c}" required="true">
                    <apex:actionSupport event="onchange" rerender="pageBlockSection" status="channelStatus"/>
                </apex:inputField>
                <apex:actionStatus startText="applying change..." id="channelStatus"/>
                <apex:inputField value="{!Marketing_Request__c.Other_Channel__c}" required="true" rendered="{!Marketing_Request__c.Channel__c == 'Other'}" id ="otherChannelId"/>
            </apex:pageBlockSection>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

Thanks,
pRAMODH.

All Answers

Swayam@SalesforceGuySwayam@SalesforceGuy
Hi,

There is problem while using required = true and Immediate = true while using action support, you need to use Action region to achieve the functionality 

Updated Code 
<apex:page standardController="Marketing_Request__c">
    <apex:sectionHeader title="Edit Marketing Request" subtitle="{!Marketing_Request__c.Name}"/>
    <apex:form>
        <apex:pageBlock title="Edit Marketing Request" id="thePageBlock" mode="edit">
            
            <apex:pageMessages id="pageMessage"/>
            
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection title="Branding and Channel" columns="1">
                <apex:inputField value="{!Marketing_Request__c.Branding_Type__c}" required="true"/>
                <apex:inputField value="{!Marketing_Request__c.Channel__c}" required="true" onchange="showChannelStatus();" />

				<apex:actionRegion>
					<apex:actionFunction name="showChannelStatus"  rerender="thePageBlock,pageMessage" immediate="true" status="channelStatus" >
					</apex:actionFunction>
					  <apex:actionStatus startText="applying change..." id="channelStatus"/>
				</apex:actionRegion>					 

                <apex:inputField value="{!Marketing_Request__c.Other_Channel__c}" required="true" rendered="{!Marketing_Request__c.Channel__c == 'Other'}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Hope this helps

--
Thanks,
Swayam

 
kory108kory108
Swayam,

Thank you for the quick response! After applying your updated code I'm now experiencing an issue where the data in the inputFields are cleared out anytime a new value is selected from the Channel picklist. It appears the system is correctly updating the page, however the data the user entered previous to the actionFunction update is not saved.
Pramodh KumarPramodh Kumar
Hey Kory


when you try to rerender the pageblock entire block will be refreshed. Instead you only refresh part of the block.


Please try this code and let me know if you have any problems
 
<apex:page standardController="Marketing_Request__c">
    <apex:sectionHeader title="Edit Marketing Request" subtitle="{!Marketing_Request__c.Name}"/>
    <apex:form>
        <apex:pageBlock title="Edit Marketing Request" id="thePageBlock" mode="edit">
            
            <apex:pageMessages />
            
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            
            <apex:pageBlockSection title="Branding and Channel" columns="1" id="pageBlockSection">
                <apex:inputField value="{!Marketing_Request__c.Branding_Type__c}" required="true"/>
                <apex:inputField value="{!Marketing_Request__c.Channel__c}" required="true">
                    <apex:actionSupport event="onchange" rerender="pageBlockSection" status="channelStatus"/>
                </apex:inputField>
                <apex:actionStatus startText="applying change..." id="channelStatus"/>
                <apex:inputField value="{!Marketing_Request__c.Other_Channel__c}" required="true" rendered="{!Marketing_Request__c.Channel__c == 'Other'}" id ="otherChannelId"/>
            </apex:pageBlockSection>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

Thanks,
pRAMODH.
This was selected as the best answer
kory108kory108
pRAMODH,

Thank you very much - that works perfectly!