+ Start a Discussion
RDN_LHRRDN_LHR 

Trying to Conditionally Render a field -- help!!

Hi,

 

I'm trying to render the field "Opportunity__c" only when the user changes the Lead.status to "Part of an Existing Opportunity."  I have a feeling that I'm close, after trying to adapt the examples in the documentation but there's still something not right.

 

Hopefully this is easy for someone to point out?

 

Thanks ....

 

<apex:page standardController="Lead" extensions="leadConverter2">
<apex:form >
  <apex:pageBlock title="Fill in the following">
   <apex:pageBlockSection columns="2">
     <apex:outputField value="{!lead.id}"/>
     <apex:outputField value="{!lead.name}"/>
       <apex:actionRegion>
          <apex:inputField required="true" id="ls" value="{!lead.status}">
            <apex:actionsupport event="onchange" rerender="opp" />
          </apex:inputField>
       </apex:actionRegion>


   <apex:outputPanel id="opp">
      <apex:inputField rendered="{!lead.status == 'Part of an Existing Opportunity'}" required="true" value="{!lead.Opportunity__c}"/>
   </apex:outputPanel>
  </apex:pageBlockSection>      

  <apex:pageBlockButtons location="bottom">
     <apex:commandButton value="Submit" action="{!convertLeadNoOpp_2}"/>
  </apex:pageBlockButtons>
  </apex:pageBlock>

</apex:form>
</apex:page>

 

wesnoltewesnolte

Hey

 

The issue is that you aren't submitting the form so the value in the inputField hasn't yet been assigned to lead.status.

 

As far as I know(and perhaps someone else can enlighten me here) you have a few options

 

1. include an action method on <apex:actionsupport event="onchange" rerender="opp" /> although that may fire for every letter that is typed, but I'd try it out anyway.

 

2. Use an actionfunction instead of actionsupport, and create some javascript to get the field value out of the inputField and do the comparison.

 

Cheers,

Wes 

Edwin VijayEdwin Vijay

Try the following...

 

Use immediate="true" in your actionsupport...  Sometimes, validation errors may not cause your actionsupport to be fired..

 

You can always check the debug log or the system log to find what's going wrong where.. 

 

Hope this helps... 

TehNrdTehNrd

wesnolte wrote:

 

1. include an action method on <apex:actionsupport event="onchange" rerender="opp" /> although that may fire for every letter that is typed, but I'd try it out anyway.

 


I would agree with trying this method first. On a rerender no values are being set in the extension so the rendered formula will always evaluate to false.

 

Here is also a tidbit that may help with debugging.

<apex:actionRegion>
<apex:inputField required="true" id="ls" value="{!lead.status}">
<apex:actionsupport event="onchange" rerender="opp" />
</apex:inputField>
</apex:actionRegion>


<apex:outputPanel id="opp">
<!--Added one little line here so you can see what the value of lead.status is-->
{!lead.status}
<apex:inputField rendered="{!lead.status == 'Part of an Existing Opportunity'}" required="true" value="{!lead.Opportunity__c}"/>
</apex:outputPanel>
</apex:pageBlockSection>

 

 

Message Edited by TehNrd on 07-27-2009 09:56 AM