confirmBillableYesEdit

confirmBillableYesEdit

当在toggleBillableChkBox方法中切换其值时,我想防止触发selectbooleancheckbox的onchange事件。

<p:selectBooleanCheckbox value="#{myBean.billableBoolean}" widgetVar="billableEditVar"
    id="billableEdit" onchange="showBillableForEdit(this)">
</p:selectBooleanCheckbox>

function showBillableForEdit(obj){
     if(obj.checked){
        confirmBillableYesEdit.show();
    } else{
        confirmBillableNoEdit.show();
    }
}


<p:confirmDialog id="confirmBYesEditId" header="Please Confirm" severity="alert" visible="false"
    widgetVar="confirmBillableYesEdit"
    message="edit Are you sure  you want to invoice this service ?" >
    <p:commandButton value="Yes" oncomplete="confirmBillableYesEdit.hide();" global="false" >
    </p:commandButton>

    <p:commandButton value="No"   onclick="toggleBillableChkBox();"
        oncomplete="confirmBillableYesEdit.hide();">
    </p:commandButton>
</p:confirmDialog>


function toggleBillableChkBox() {
    billableEditVar.toggle();
}

最佳答案

您无法阻止触发该事件,但是您可以使用此代码停止该事件的执行。 (这将替换您的onclick)在脚本标签中:

$('#billableEdit').on('change', function( evt ) {
  evt.preventDefault();
  evt.stopPropagation();
  billableEditVar.toggle();
});

07-27 21:23