denfri.dev
denfri.dev

Reputation: 181

How to disable p:defaultCommand when blockUI is active?

I am using Primefaces 7.0 and want to disable the defaultCommand when the blockUI is active... My Problem is, when i hit the SaveButton the blockUI is active, but i can still press ENTER and the defaultCommand gets triggered. How can i disable this? I dont want to disable the defaultCommand always.

<h:form id="form">  

    <p:panel id="pnlContent">
        <p:commandButton value="SaveButton" id="btnSave" action="#{defaultView.longRunningOperation}"/>

        <p:defaultCommand target="btnSave"/>
    </p:panel>

    <p:blockUI block="pnlContent" trigger="btnSave"/>

</h:form>

Upvotes: 2

Views: 390

Answers (1)

Selaron
Selaron

Reputation: 6184

You can drop the focus from all components within the blocked panel by invoking JQuery.blur() on them:

<p:commandButton value="SaveButton" id="btnSave"
    onclick="$(PrimeFaces.escapeClientId('form:pnlContent') + ' *').blur()" />

This will prevent additional command invocations on subsequent pressing of enter.

Upvotes: 4

Related Questions