Not getting an inputField to rerender an using onchange event. It will fire if I click out of the inputfield. Any ideas?

<apex:component controller="PROD_CCRA_LOB_NonStdAutoController" >
<apex:attribute name="NonStdAuto" type="CCRA_LOB_NonStdAuto__c" assignTo="{!NonStdAutoObj}" description="CCRA non standard auto LOB" required="true"/>    
<apex:attribute name="record" type="Claims_Client_Risk_Assessment__c" description="CCRA Parent Object" required="true"/> 
<apex:form id="form1">
<apex:pageBlock id="block1" dir="" >
<apex:actionRegion immediate="true" > 

<apex:outputPanel Style="width:100%;" layout="block">
<apex:pageBlockSection id="Summary" title="" columns="2" showHeader="false" >
  <apex:pageBlockSectionItem dataStyleClass="col"  >
    <apex:outputLabel value="Does Client perform adequate investigations to confirm coverage for driver and vehicle at issue?"  StyleClass="col1"   />
     <apex:inputField value="{!NonStdAuto.Client_perform_adequate_investigation__c}" styleClass="col2" > 
        <apex:actionSupport event="onchange" reRender="NSA1a,NSA1b,NSA1c" / >                    
   <apex:pageBlockSectionItem dataStyleClass="col"  >                         
   <apex:outputLabel value=""   /> 

<apex:pageBlockSectionItem dataStyleClass="col"  >
    <apex:outputPanel id="NSA1a">
     <apex:outputLabel value="Please comment as needed to describe the diligence of their coverage investigation:"  StyleClass="col4" rendered="{!IF(CONTAINS(NonStdAuto.Client_perform_adequate_investigation__c,'Yes'),true,false)}"   /> 

    <apex:outputPanel id="NSA1b">
       <apex:inputField value="{!NonStdAuto.Comment_diligence_coverage_investigation__c}" styleClass="inputFieldStyle1" rendered="{!IF(CONTAINS(NonStdAuto.Client_perform_adequate_investigation__c,'Yes'),true,false)}" >                  
          <apex:actionSupport event="onchange" reRender="NSA1b" / >  

<apex:pageBlockSectionItem dataStyleClass="col"  >
    <apex:outputPanel id="NSA1c">                                               
       <apex:outputLabel value=""  rendered="{!IF(CONTAINS(NonStdAuto.Client_perform_adequate_investigation__c,'Yes'),true,false)}"  /> 

  • What is the data type of your input fields. The behavior you are mentioning makes me think they are text fields, is that correct? Also, you have several onchange events here which one specifically is causing your issue? – gNerb Jul 25 '18 at 21:22
  • @gNerb yes the field type is text. Apologies, it is reRender=“NSA1b” – rickmac Jul 25 '18 at 21:27
  • sorry I've been fighting with myself on what I wanted to put into the answer. I think I've settled on the content so if you haven't already, give it another read. – gNerb Jul 25 '18 at 21:48

Your rerender=nas1b should be complete removed from the page.

The output panel only contains the 1 input element and when that element is changed you're re-rendering the same input element. That's like saying "if someone types "a" into this field, remove the value and put "a" back into it" there's not much point in doing this unless your sample is missing some code.

Onchange with Textboxes

Text boxes, for good reason, do not fire onchanged events every time a letter is typed in. The built in text boxes onchange event behaves more like an onblur as you have noticed. When we needed to fire an onchange on every keypress we used onkeyup

| improve this answer | |
  • Will try but I’m rendering the visualforce component from a parent Visualforce page. Rerendering seems to allow the fields to be saved by a simple upsert in the parent controller. – rickmac Jul 25 '18 at 22:21
  • Leaving out the rerender="NSA1b" and keeping the onchange event on the actionsupport reloads the whole page. Given the nature of onchange and text fields I need a way to focus off a text field when user selects to save the form. Unless the user moves off the text field it will not be saved when the upsert occurs from the parent on the visualforce component's object record. Not sure what the best approach is . @gNerb – rickmac Jul 26 '18 at 1:15
  • if I move the focus off the inputField from the controller's save method then that would work but not sure setting the focus to another field can be done in apex ? – rickmac Jul 26 '18 at 2:37

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.