I want a picklist with 2 options, yes and no, if the user selects No, a new field should show up for the user to enter an Amount, if the user leaves it on Yes then nothing happens and they can click on "Save". When "No" is selected on the picklist field, nothing happens.
<apex:pageBlock TITLE="Open an Account for this Company">
<apex:outputText value="blah blah"/>
<apex:pageBlockSection>
<apex:selectList value="{!optionSelected}" multiSelect="false" size="1">
<apex:selectOption itemValue="Yes" itemLabel="Yes"/>
<apex:selectOption itemValue='No' itemLabel="No"/>
<apex:actionSupport reRender="loadAmount" event="onChange" action="{!displayAmount}"/>
</apex:selectList>
<!-- What to Re-render and When -->
<apex:outputPanel id="loadAmount">
<apex:pageBlockSectionItem rendered="{!optionSelected=='No'}">
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock"/>
<apex:inputText value="{!opportunityAmount}" required="true" styleClass="requiredInput" />
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:outputPanel>
</apex:pageBlockSection>
<br/>
<br/>
<apex:commandButton id="saveBtn" value="Save" action="{!save}" />
</apex:pageBlock>
The following section is supposed to show whenever a the selected option is "No" but it never shows up. What could the issue be and how would you re-write the code?
<apex:outputPanel id="loadAmount">
<apex:pageBlockSectionItem rendered="{!optionSelected=='No'}">
<apex:outputPanel styleClass="requiredInput" layout="block">
<apex:outputPanel styleClass="requiredBlock"/>
<apex:inputText value="{!opportunityAmount}" required="true" styleClass="requiredInput" />
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:outputPanel>
displayAmount()
method from your controller/extension. – Derek F Apr 13 '17 at 15:19displayAmount()
is your culprit is to remove it from theaction
attribute of your<apex:actionSupport>
(so you'd just haveaction=""
). If you do that, and the re-render starts working, then your issue is withdisplayAmount()
. – Derek F Apr 13 '17 at 15:19