使用VisualForce中的输入字段有选择地隐藏pageBlocks

时间:2012-09-25 17:27:05

标签: salesforce visualforce

我想仅在inputField“Gift_ c.PaymentMethod _c”(这是下拉列表)具有特定值(即“信用卡”)时才显示pageBlockSection“ccBlock”。到目前为止,我尝试了许多方法,但没有运气。

    <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 个答案:

答案 0 :(得分:1)

您的解决方案无效,因为您尝试重新调整已隐藏的pageBlockSection,因此您无权访问此部分。为此,您需要重新设置一些“包装”面板。

我喜欢用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>
相关问题