You need to sign in to do that
Don't have an account?

Render based on the picklist Value selection
Hi,
I am unable to get this to work.
I am trying to render a pageblock based on the selection of the picklist value. if the Opportunitystage=='Qualification' i want to then render the close date field.
in the below code i want to display the Closedate only when an Opportunity stage is selected and equals to "Qualification"
I don't know if i am doing any AJAX requests incorrectly.Can any one help me with this.
Page:
<apex:page standardController="Opportunity"> <apex:form > <apex:pageBlock title="Edit Opportunity" id="thePageBlock" mode="edit"> <apex:pageBlockButtons location="bottom" > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockSection columns="1"> <apex:inputField value="{!opportunity.name}"/> <apex:pageBlockSectionItem > <apex:outputLabel value="{!$ObjectType.opportunity.fields.stageName.label}" for="stage"/> <!-- Without the actionregion, selecting a stage from the picklist would cause a validation error if you hadn't already entered data in the required name and close date fields. It would also update the timestamp. --> <apex:actionRegion renderRegiononly="{!opportunity.stageName !='Qualification'}" > <apex:inputField value="{!opportunity.stageName}" id="stage"> <apex:actionSupport event="onchange" rerender="ajaxrequest" status="status"/> </apex:inputField> </apex:actionRegion> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:outputPanel id="ajaxrequest" rendered="{!Opportunity.StageName}" > <apex:inputField value="{!Opportunity.CloseDate}"/> {!text(now())} </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>
Thanks,
Sales4ce
First of all you need to remove the renderRegionOnly attribute on your actionRegion component -- that is not doing what you think it's doing. Simply surrounding your inputField with an actionRegion will submit only that inputField without submitting the values outside of it (as you've alluded to in your HTML comment).
Whatever you want to be conditionally rendered should have rendered="{!Opportunity.StageName != 'Qualification'}" because that is the expression that will be evaluated whenever that component is created or updated.
And then finally, the target of what you are rerendering needs to always be on your page -- in more basic terms, whatever id you specify in rerender="someId" cannot be on the same component that has the rendered="{!Opportunity.StageName != 'Qualification'}" on it. So if you want your outputPanel conditionally rendered, it can't be the target of your rerender attribute. You may need to put it inside of another outputPanel. For more explanation see this thread: http://boards.developerforce.com/t5/Visualforce-Development/Dynamic-hiding/m-p/79589
All Answers
First of all you need to remove the renderRegionOnly attribute on your actionRegion component -- that is not doing what you think it's doing. Simply surrounding your inputField with an actionRegion will submit only that inputField without submitting the values outside of it (as you've alluded to in your HTML comment).
Whatever you want to be conditionally rendered should have rendered="{!Opportunity.StageName != 'Qualification'}" because that is the expression that will be evaluated whenever that component is created or updated.
And then finally, the target of what you are rerendering needs to always be on your page -- in more basic terms, whatever id you specify in rerender="someId" cannot be on the same component that has the rendered="{!Opportunity.StageName != 'Qualification'}" on it. So if you want your outputPanel conditionally rendered, it can't be the target of your rerender attribute. You may need to put it inside of another outputPanel. For more explanation see this thread: http://boards.developerforce.com/t5/Visualforce-Development/Dynamic-hiding/m-p/79589
Thanks for your timely reply. i have modified the code per your advice and it worked like charm.
Thanks for your help.
This is the updated/working code for future reference.
Thank you for posting the working code. This helped resolve my issue.
Thank You for the solution this helped me a lot
Is it possible with VForce?