0

I can't figure out what it is I am doing wrong with this code. I would like to only render the Service_Account__c.CM_Service__c field based upon the value of the checkbox field Service_Account__c.To_be_used__c.

As it is now, the CM_Service__c field will never render, regardless of what values I put into the logic true or false.

<apex:pageblocksection title="Settings (If Applicable)" showheader="true" columns="1" >
     <apex:inputfield value="{!Service_Account__c.To_be_used__c}" required="false"> 
       <apex:actionSupport event="onchange" reRender="SERV" />                    
     </apex:inputField>

     <apex:inputfield id="SERV" value="{!Service_Account__c.CM_Service__c}" required="false" rendered="{IF(!Service_Account__c.To_be_used__c == true,true,false)}" />                         
</apex:pageblocksection>

Any ideas ? Is it just a syntax error I'm not catching...?

3

You need to rerender the parent element with conditionally rendered elements

<apex:pageblocksection id="rerenderme" title="Settings (If Applicable)" showheader="true" columns="1" >
     <apex:inputfield value="{!Service_Account__c.To_be_used__c}" required="false"> 
       <apex:actionSupport event="onchange" reRender="rerenderme" />                    
     </apex:inputField>

     <apex:inputfield id="SERV" value="{!Service_Account__c.CM_Service__c}" required="false" rendered="{!Service_Account__c.To_be_used__c}" />                         
</apex:pageblocksection>

And your rendered attribute can be shortened to just the field value (also fixing the improper IF which was written incorrectly but was not needed anyway)

  • Thank you very much. Do the two fields need to be part of the same block section in order for the rerender to work ? – Zoom_v Sep 29 '17 at 16:07
  • 1
    @Zoom_v - No, just the same form – Eric Sep 29 '17 at 17:53

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.