如何根据选中或未选中的复选框禁用顶点命令按钮



我正在为我的公司创建一个visualforce页面,除非页面上的复选框更改,否则我希望禁用提交按钮。我可以用常规输入按钮来完成这项工作,但我需要用Apex命令按钮来完成,这样我就可以让他们更新记录,从而启动后端进程。

这是我的代码

<apex:page standardController="RMA__c">
<apex:form >
<apex:outputPanel id="thePanel" rendered="{!(RMA__c.RLI_has_QUOTE_SO__c == true)}">
<apex:pageBlock id="TheBlock" title="Confirm Information" mode="edit">
<apex:pageBlockSection id="theSection" title="Confirm the  new field values" columns="2" rendered="{!(RMA__c.Show_the_box__c == true)}">
<apex:outputfield value="{!RMA__c.Contact__c}"/>
<apex:outputfield value="{!RMA__c.Shipping_Priority__c}"/>
<apex:outputfield value="{!RMA__c.Ship_to_Address__c}"/>
<apex:outputfield value="{!RMA__c.Bill_to_Address__c}"/>
<apex:inputfield value="{!RMA__c.Request_Priority__c}"/>
<apex:inputField id="reviewed" value="{!RMA__c.Changes_are_reviewed__c}"/> 
</apex:pageBlockSection>
<apex:pageblockButtons id="button">
<apex:commandButton value="Submit" action="{!save}" id="saveit" disabled="true"/>
</apex:pageblockButtons>
<script>
var checker = document.getElementById("{!$Component.TheBlock.theSection.reviewed}");
var sendbtn = document.getElementById("{!$Component.TheBlock.button.saveit}");
checker.onchange = function()
{
if(this.checked)
{
sendbtn.disabled = false;
} 
else 
{
sendbtn.disabled = true;
}
}
</script>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>

您可以在RMA__c.Changes_are_reviewed_c输入字段中使用reRender属性

首先,用<apex:outputpanel>包裹命令按钮

<apex:outputpanel>
<apex:commandButton value="Submit" action="{!save}" id="saveit" disabled="{!RMA__c.Changes_are_reviewed__c==false}"/>
</apex:outputpanel>

然后,从重新发送

<apex:inputField id="reviewed" value="{!RMA__c.Changes_are_reviewed__c}" reRender="saveit"/>

希望,这会有所帮助。我没有在salesforce中编译代码,可能有一些编译错误。但是,通过这种方式,它会起作用。

最新更新