Find your content:

Search form

You are here

How to make a Lookup Field trigger a reRender to make other fields visible?

 
Share

I have an APEX page with a few fields and some buttons. Initially, the first field (a lookup field) is the only one that is shown. I would like to be able to show the other fields once the user has selected a value from the lookup window.

Currently, I am using rendered={!isFieldSet == true} in the fields I want to hide until later, but I am unable to update this value and get the fields to appear. I am currently using a javascript onchange method to call the controller method to set the isFieldSet value. But when I examine the property from javascript, it does not see the change to the isFieldSet, I guess because the page has not been reloaded? I am wondering what the standard way to get this sort of thing to work is. Currently I am trying to reload the page using url arguments, but the lookup field value is not coming through to the backend.

Here is some code for reference.

    <apex:inputField value="{!objectReference.propertyName}" required="true" onchange="actionpropertyValueChanged();">

Here is the code for hiding a section:

    <apex:pageBlockSectionItem rendered="{!isFieldSet == true}" id="daySelectorBlock">
         ...
    </apex:pageBlockSectionItem>

Attribution to: lindon fox

Possible Suggestion/Solution #1

apex:actionSupport can be used to rerender a component via AJAX when a change is made to the inputField.

<apex:actionStatus startText="Wait." stopText="" id="inputFieldActionStatus"/>
<apex:inputField value="{!objectReference.propertyName}" required="true" >
     <apex:actionSupport action="{!someControllerMethod}" status="inputFieldActionStatus" 
         event="onclick" rerender="daySelectorBlock">
         // You might want an apex:Param here to pass the inputField value back via ajax
     </apex:actionSupport>
</apex:inputField>

<apex:pageBlockSectionItem rendered="{!isFieldSet}" id="daySelectorBlock">
    //...
</apex:pageBlockSectionItem>

After the AJAX call to the server the pageBlockSectionItem should render if isFieldSet is set to true via the method someControllerMethod.


Attribution to: Daniel Ballinger
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4998

My Block Status

My Block Content