1
votes

I would like to display the pageBlockSection "ccBlock" only if the inputField "Gift_c.PaymentMethod_c" (which is a Dropdown) has a certain value - namely 'Credit Card'. I've tried many approaches but no luck so far.

    <apex:pageBlockSection title="Basic Information" columns="1" >
        <apex:inputField value="{!Gift__c.Contact__c}"/>
        <apex:inputField value="{!Gift__c.PaymentMethod__c}" id="payMethod" >
            <apex:actionSupport event="onchange"  reRender="ccBlock, bankBlock" action="{!HideBlock}" />
        </apex:inputField>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Credit Card" rendered="{!visi}" columns="1" id="ccBlock">
        <apex:inputField value="{!Gift__c.CCType__c}"/>
        <apex:inputField value="{!Gift__c.CCName__c}"/>
        <apex:inputField value="{!Gift__c.CCNumber__c}"/>
        <apex:inputField value="{!Gift__c.CCExpiryMonth__c}"/>
        <apex:inputField value="{!Gift__c.CCExpiryYear__c}"/>
    </apex:pageBlockSection>  
1
Are you using a controller or controller extension? - JCD
Would you mind pasting some of that code as well, especially if you have any logic around any of the fields referenced in your VF markup? - JCD
@JCD I don't have any logic in the Extension class for the fields per se. It's all populated by the DB automagically from Salesforce. I've tried creating a method called "visi" that looks up the value of "PaymentMethod__c" ( a drop down) but the DB field isn't populated when it's called, and I don't know any way to look up the value of the HTML element (which may not even be set at that point in the lifecycle). - Daniel
Rather than having your visi method look up the value of the Gift__c.PaymentMethod__c field in the database, you need to be checking the value of the record in memory (since the changes haven't been persisted yet). Do you have any kind of call to ApexPages.StandardController.getRecord() in your controller's constructor? - JCD

1 Answers

1
votes

Your solution did not work because you tried to reRender the pageBlockSection that was already hided, so you do not have access to this section. For that you need some "wrapper" panel to be reRendered.

I preffer to do things like this just with a javascript:

<apex:pageBlockSection title="Basic Information" columns="1" >
    <apex:inputField value="{!Gift__c.Contact__c}"/>
    <apex:inputField value="{!Gift__c.PaymentMethod__c}" id="payMethod" onchange="checkValue()"/>
</apex:pageBlockSection>

<apex:outputPanel style="display:none;" id="myPanel">
    <apex:pageBlockSection title="Credit Card" rendered="{!visi}" columns="1" id="ccBlock">
        <apex:inputField value="{!Gift__c.CCType__c}"/>
        <apex:inputField value="{!Gift__c.CCName__c}"/>
        <apex:inputField value="{!Gift__c.CCNumber__c}"/>
        <apex:inputField value="{!Gift__c.CCExpiryMonth__c}"/>
        <apex:inputField value="{!Gift__c.CCExpiryYear__c}"/>
    </apex:pageBlockSection>  
</apex:outputPanel>

<script>
function checkValue(){
    if(jQuery('[id$=payMethod]').val() == 'Credit Card'){
        jQuery('[id$=myPanel]').show();
    }
    else{
        jQuery('[id$=myPanel]').hide();
    }
}
</script>