DD.
DD.

Reputation: 21981

Prevent double click except when validation error

<p:commandButton id="checkout" 
   value="Checkout" 
   action="#{checkoutBean.checkout}" 
   update="@form"
   onclick="setTimeout('document.getElementById(\'' + this.id + '\').disabled=true;', 50);"/>

On my checkout button I use the timeout hack to prevent double clicks... However if the validation fails (e.g. the user puts in an invalid card number), the button is disabled and they can't enter the correct details.

How do I work around this?

Upvotes: 0

Views: 433

Answers (1)

Hatem Alimam
Hatem Alimam

Reputation: 10048

To prevent having duplicate calls to the checkout you can use onstart and oncomplete,

onstart="PF('checkoutWV').disable()" 
oncomplete="PF('checkoutWV').enable()"

checkoutWV is the widgetVar of the button.

Upvotes: 2

Related Questions