function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jay PollackJay Pollack 

Render Field based on Picklist Value

I am trying to render a picklist when a certain value is selected on a previous picklist.  Right now picklist #2 does not render, when I change the value on picklist 1 I see the screen flash, but #2 does not render.  Any suggestions are appreciated.

 

Controller:

public with sharing class WPCaseAction {

public Case_Action__c ca; //Case Action sobject
public Boolean actionIsCloseCase { get; set;}

//initializes the private member variable by using the getRecord method from the standard controller
public WPCaseAction (ApexPages.StandardController stdController)
{
this.ca = (Case_Action__c )stdController.getRecord();

if (ca.case__c!= null)
{
Case c = [select Current_Stage__c, Status, Next_Step__c from Case where id =: ca.case__c limit 1];
ca.Stage__c = c.Current_Stage__c;
ca.Case_Status__c = c.Status;
ca.Next_Step__c = c.Next_Step__c;
}

}


public List<SelectOption> getAct() {

List<SelectOption> options = new List<SelectOption>();

if (ca.Case_Status__c == 'Closed')
{
options.add(new SelectOption('Re-Open Case','Re-Open Case'));
}

if (ca.Stage__c == '0 - Define Specifications' && ca.Case_Status__c != 'Closed')
{
options.add(new selectOption('', '- Please Select an Action -'));
options.add(new SelectOption('Submit Request to Integration Team','Submit Request to Integration Team'));
options.add(new SelectOption('Close Case','Close Case'));
options.add(new SelectOption('Place Request on Hold','Place Request on Hold'));
}


else if (ca.Stage__c == '1 - Review Specifications' && ca.Case_Status__c != 'Closed')
{
options.add(new selectOption('', '- Please Select an Action -'));
options.add(new selectOption('Request Information - Return to Case Creator', 'Request Information - Return to Case Creator'));
options.add(new selectOption('Provide Information - Return to IC', 'Provide Information - Return to IC'));
options.add(new selectOption('Assign Request to Create Export - to IC', 'Assign Request to Create Export - to IC'));
options.add(new selectOption('Submit Request to Technical Team', 'Submit Request to Technical Team'));
options.add(new SelectOption('Close Case','Close Case'));
options.add(new SelectOption('Place Request on Hold','Place Request on Hold'));
}

else if (ca.Stage__c == '2 - Create Export' && ca.Case_Status__c != 'Closed')
{
options.add(new selectOption('', '- Please Select an Action -'));
options.add(new selectOption('Assign Request to Create Export - to TC', 'Assign Request to Create Export - to TC'));
options.add(new selectOption('Request Information - Return to IC', 'Request Information - Return to IC'));
options.add(new selectOption('Request Information - Return to Case Creator', 'Request Information - Return to Case Creator'));
options.add(new selectOption('Provide Information - Return to TC', 'Provide Information - Return to TC'));
options.add(new selectOption('Provide Information - Return to IC', 'Provide Information - Return to IC'));
options.add(new selectOption('Submit Export for Testing', 'Submit Export for Testing'));
options.add(new SelectOption('Close Case','Close Case'));
options.add(new SelectOption('Place Request on Hold','Place Request on Hold'));
}

else if (ca.Stage__c == '3 - Testing' && ca.Case_Status__c != 'Closed')
{
options.add(new selectOption('', '- Please Select an Action -'));
options.add(new selectOption('Submit Export for Testing', 'Submit Export for Testing'));
options.add(new selectOption('Testing - Waiting on Customer', 'Testing - Waiting on Customer'));
options.add(new selectOption('Testing - Waiting on Case Creator', 'Testing - Waiting on Case Creator'));
options.add(new selectOption('Testing - Waiting on TC', 'Testing - Waiting on TC'));
options.add(new selectOption('Testing - Waiting on Vendor', 'Testing - Waiting on Vendor'));
options.add(new selectOption('Approve Export for Scheduling', 'Approve Export for Scheduling'));
options.add(new SelectOption('Close Case','Close Case'));
options.add(new SelectOption('Place Request on Hold','Place Request on Hold'));
}

else if (ca.Stage__c == '4 - Schedule Export' && ca.Case_Status__c != 'Closed')
{
options.add(new selectOption('', '- Please Select an Action -'));
options.add(new SelectOption('Close Case','Close Case'));
options.add(new SelectOption('Place Request on Hold','Place Request on Hold'));
}

return options;
}


public List<SelectOption> getReasonCode()
{

List<SelectOption> options = new List<SelectOption>();

options.add(new selectOption('', 'Client Changing Vendors'));
options.add(new selectOption('', 'Client Decided Against Electronic Feeds'));
options.add(new selectOption('', 'Client Resources Unable to Commit'));
options.add(new selectOption('', 'Other – Miscellaneous'));
options.add(new selectOption('', 'Request Made in Error'));
options.add(new selectOption('', 'Vendor Cannot Accept Electronic Feeds from US'));


return options;
}

public pagereference reloadReasonsPicklistRender()
{
 if(action == 'Close Case')
actionIsCloseCase = true;
else actionIsCloseCase = false;

return null;
}

}

 

Visual Force Page:

<apex:page standardController="Case_Action__c" extensions="WPCaseAction" >
<apex:form >

<apex:actionFunction name="jsReloadReasonsPicklistRender" action="{!reloadReasonsPicklistRender}" rerender="ReasonPanel" status="myStatus" />


<apex:pageBlock title="Action" mode="mainDetail" ID="CaseAction">
<apex:pageblockButtons >
<apex:commandButton action="{!Save}" Value="Save" />
<apex:commandButton action="{!Cancel}" Value="Cancel" />
</apex:pageblockButtons>

<apex:pageBlockSection columns="1">
<apex:pageMessages >
</apex:pagemessages>
</apex:pageBlockSection>


<apex:pageBlockSection title="Case Information" columns="1">
<apex:outputfield value="{!Case_Action__c.Case__c}"/>
<apex:outputfield value="{!Case_Action__c.Case_Status__c}"/>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Current Stage" ></apex:outputLabel>
<apex:outputText > {!Case_Action__c.Stage__c} </apex:outputText>
</apex:pageBlockSectionItem>


<apex:pageBlockSectionItem >
<apex:outputLabel value="Next Step" ></apex:outputLabel>
<apex:outputText > {!Case_Action__c.Next_Step__c} </apex:outputText>
</apex:pageBlockSectionItem>

</apex:pageBlockSection>

<apex:pageBlockSection Title="Action" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Action" ></apex:outputLabel>
<apex:selectList id="act" value="{!Case_Action__c.Action__c}" size="1" Title="Action" onchange="jsReloadReasonsPicklistRender();" >
<apex:selectOptions value="{!act}">
</apex:selectOptions>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:actionStatus startText="Refreshing..." id="myStatus"/>

<apex:outputpanel id="ReasonPanel" rendered="actionIsCloseCase">
<apex:pageBlockSection columns="1" >

<apex:pageBlockSectionItem >

<apex:outputLabel value="Reason" ></apex:outputLabel>
<apex:selectList value="{!Case_Action__c.Reason_Code__c}" size="1" >
<apex:selectOptions value="{!ReasonCode}">
</apex:selectOptions>
</apex:selectList>

</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:outputpanel >

<apex:pageBlockSection columns="1">

<apex:inputField value="{!Case_Action__c.Requested_By_Date__c}" required="true"/>
<apex:inputField value="{!Case_Action__c.Follow_Up_Date__c}" required="true"/>

</apex:pageBlockSection>

<apex:pageBlockSection columns="1" >

</apex:pageBlockSection>
<apex:pageBlockSection columns="1">
<apex:outputtext />
<apex:inputfield value="{!Case_Action__c.Comments__c}" required="true" style="width:75%;"/>
</apex:pageBlockSection>


</apex:pageBlock>

<apex:actionStatus startstyle="color:green;" startText="Updating page ..." id="StatusChange"/>

<script>function setFocusOnLoad() {}</script>

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


Navatar_DbSupNavatar_DbSup

Hi,

 

try below code sample:

<apex:selectList id="act" value="{!Case_Action__c.Action__c}" size="1" Title="Action" >
<apex:actionSupport event="onchange" action="{!reloadReasonsPicklistRender}" reRender="ReasonPanel" status="myStatus"/>
<apex:selectOptions value="{!act}">
</apex:selectOptions>
</apex:selectList>


<apex:selectList value="{!Case_Action__c.Reason_Code__c}" size="1" >
<apex:selectOptions value="{!ReasonCode}">
</apex:selectOptions>
</apex:selectList>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Jay PollackJay Pollack

No - still have the same issue.  When I change the Action Picklist, the screen flashes, but the Reason picklist does not render.

Navatar_DbSupNavatar_DbSup

Hi,

 

try the below sample

 

<apex:pageBlockSection Title="Action" columns="1">

<apex:outputLabel value="Action" ></apex:outputLabel>
<apex:selectList id="act" value="{!Case_Action__c.Action__c}" size="1" Title="Action" >
<apex:actionSupport event="onchange" action="{!reloadReasonsPicklistRender}" reRender="ReasonPanel" status="myStatus"/>
<apex:selectOptions value="{!act}">
</apex:selectOptions>
</apex:selectList>

</apex:pageBlockSection>

<apex:actionStatus startText="Refreshing..." id="myStatus"/>

<apex:pageBlockSection columns="1" id="ReasonPanel">
<apex:outputLabel value="Reason" ></apex:outputLabel>
<apex:selectList value="{!Case_Action__c.Reason_Code__c}" size="1" >
<apex:selectOptions value="{!ReasonCode}">
</apex:selectOptions>
</apex:selectList>
</apex:pageBlockSection>

 

Remove output panel and page block section item .here already remove from above code.

Jay PollackJay Pollack

appreciate the help - but same thing.