Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable button in JQuery dialog

Tags:

jquery

I can disable it fine using this:

button.attr('disabled', 'disabled' ).addClass( 'ui-state-disabled' );

But how do I re-enable it? When I use this:

button.attr('enabled', 'enabled' ).addClass( 'ui-state-enabled' );

It doesn't work.

like image 557
slandau Avatar asked Jan 27 '11 16:01

slandau


People also ask

How check button is disabled or not in jQuery?

Checking if the button is disabled or enabled with jQuery removeAttr('disabled'); }; const checkButton = (e) => { const isDisabled = $('#my-button'). prop('disabled'); if( isDisabled ){ alert("Is disabled!"); } else{ alert("Is enabled"); } }; $(document).

What is enable and disable button based on condition in jQuery?

Using jQuery With jQuery, you can use the . attr() method to add disabled HTML attribute to the submit button and . removeAttr() method to remove the disabled attribute from it. The value of the disabled HTML attribute indicates whether the element is enabled or disabled.

How do you make a button Unclickable in HTML?

The disabled attribute is a boolean attribute. When present, it specifies that the button should be disabled. A disabled button is unusable and un-clickable. The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.).


2 Answers

button.removeAttr('disabled').removeClass( 'ui-state-disabled' );
like image 154
Josiah Ruddell Avatar answered Oct 18 '22 22:10

Josiah Ruddell


Tried all the answers here and nothing worked for me.

The issue is that I have html:

<input type="submit" value="Save" id="saveButton" disabled="disabled" />

Then I call globaly:

$("button, input:submit, input:button").button();

After that the button gets attribute aria-disabled=true.

Neither of following will enable the submit:

$("#saveButton").attr('disabled',false);
$("#saveButton").removeAttr('disabled');
$("#saveButton").prop('disabled',false);
$("#saveButton").attr('aria-disabled',false);
$("#saveButton").removeClass('ui-state-disabled' );

The only working solution in this case is:

$("#saveButton").button( "enable" );

jQuery UI Docs: Button Widget - enable()

To disable button again:

$("#saveButton").button( "disable" );

jQuery UI Docs: Button Widget - disable()

like image 35
sumid Avatar answered Oct 18 '22 22:10

sumid