JQuery-ui: turning on a disabled button does not restore the event

I have a problem: after the power button, it looks like it is on, but it is not available for click. (reloading the page fixes this problem, but I won’t do it). First, in (document) .ready, I will disable this button.

To enable I do:

$("#submit_order").attr('disabled', false).removeClass( 'ui-state-disabled' ); 

to disable:

 $("#submit_order").attr('disabled', true).addClass( 'ui-state-disabled' ); 

HTML code:

 <button id="submit_order">Send an order</button> 
Button

JQuery Code:

 $( "#submit_order" ) .button() .click(function() { $( "#dialog-form" ).dialog( "open" ); }); 

When I pressed this button after turning on, the code above is not called.

+5
source share
4 answers

When you write

 $("#submit_order").attr(...) 

this means that you are using stanadard attributes.

You are incompatible: as soon as you use the method mentioned above, and one more time when you write:

 $( "#submit_order" ).button()..... 

try the following:

 $("#submit_order").button().attr('disabled', false).removeClass( 'ui-state-disabled' ); $("#submit_order").button().attr('disabled', true).addClass( 'ui-state-disabled' ); 
+6
source

Yes, the previous answers may work for you, but for me the events did not work when I "restarted" the button with .removeAttr ("disabled") and used .removeClass ("ui-state-disabled").

The official answer looks like

 $(".selector").button("option", "disabled", true); 

and

 $(".selector").button("option", "disabled", false); 

to enable jQueryUI () button

from http://jqueryui.com/demos/button/#option-disabled

+8
source

As I recall, jQueryUI extends the jQuery library by providing different components in which most of them have enable() and disable() methods.

You can try an alternative (more preferred option):

 $('#submit_order').button().enable(); and $('#submit_order').button().disable(); 

it frees your mind from manually managing attributes - JQUI does it yourself. This is powerful because you can create buttons using different basic elements (different methods will use them to enable and disable them) ex. The standard button uses the attribute disabled = "disabled" (browser implementation is standard)

But a button made from a snap does not support this at all.

+1
source

To enable the attempt, follow these steps:

 $('#submit_order').removeAttr('disabled').removeClass('ui-state-disabled'); 

and disable:

 $('#submit_order').attr('disabled', 'disabled').addClass('ui-state-disabled'); 
0
source

Source: https://habr.com/ru/post/944391/


All Articles