0

I am trying to reset a dependent multi-select picklist(Narrative_of_Type__c) on change of a picklist(Case_Type__c) value in a VF page. But I am not able to reset(i.e. removing the selected values) it when a I select a different value from the master picklist. Whereas I tried for a independent multiselect picklist which gets nullified with the same logic in controller. Any reason for this ?

Given below the code:

VF Page:

<apex:pageblockSection title="Request Type" columns="1">
<apex:inputField value="{!Case.Case_Type__c}">
    <apex:actionSupport event="onchange" action="{!nullifyRequestSection}" reRender="panelFirstid"/>
</apex:inputField></apex:pageblockSection>
<apex:outputPanel id="panelFirstid">
<apex:pageblockSection columns="1" rendered="{!IF(Case.Case_Type__c == 'Change Request' || Case.Case_Type__c == 'Documentation Request',true,false)}"> 
    <apex:inputField value="{!Case.Narrative_of_Type__c}"/>
</apex:pageblockSection>

Apex class:

public class Case_Controller{
private final Case testCase;
public Case_Controller(ApexPages.StandardController stdController) {
    this.testCase = (Case)stdController.getrecord();
}
public PageReference nullifyRequestSection(){
    testCase.Narrative_of_Type__c = null;
    //testCase.Narrative_of_Type__c = '';
}

}

Please suggest any solution you have for this issue. Thanks a lot in advance.

1 Answer 1

0

Dependent Picklists on the VF page come built in with the update on a controlling picklist UNLESS the use has read only access on the controlling field.

In general your page simply needs to be:

<apex:pageblockSection title="Request Type" columns="1">
   <apex:inputField value="{!Case.Case_Type__c}"/>
</apex:pageblockSection>

<apex:pageblockSection columns="1"> 
    <apex:inputField value="{!Case.Narrative_of_Type__c}"/>
</apex:pageblockSection>

1. Create a field Test_Field__c 2. Make a dependency to StageName according to your needs

As a MRE for the Opportunity (without a rerender):

<apex:page standardController="Opportunity">
<apex:form>
    <apex:pageBlock>
        <apex:pageblockSection title="Stage" columns="1">
            <apex:inputField value="{!Opportunity.StageName}"/>
        </apex:pageblockSection>

        <apex:pageblockSection columns="1"> 
            <apex:inputField value="{!Opportunity.Test_Field__c}"/>
        </apex:pageblockSection>
    </apex:pageBlock>
    </apex:form>
</apex:page>

MRE with the dependent field hidden and rerendering when the right stage is picked

<apex:page standardController="Opportunity">
<apex:form>
    <apex:pageBlock>
        <apex:pageblockSection title="Stage" columns="1">
            <apex:inputField value="{!Opportunity.StageName}">
                <apex:actionSupport event="onchange" rerender="tt"/>
            </apex:inputField>
        </apex:pageblockSection>

        <apex:outPutPanel layout="block" id="tt">
            <apex:pageblockSection columns="1" rendered="{!OR(Opportunity.StageName == 'Proof Stage' || Opportunity.StageName == 'Webinar')}"> 
                    <apex:inputField value="{!Opportunity.Test_Field__c}"/>
            </apex:pageblockSection>
        </apex:outputPanel>        
    </apex:pageBlock>
    </apex:form>
</apex:page>

Notice no controller code is needed.

So start here, verify it is working. Then add your code / customizations little by little and test along the way. If it breaks you know what broke it and can then find a way to make it work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .