I'm struggling to understand the options of enabling/disabling jquery ui buttons.
Typically in the past for any kind of button I've used:
jQuery(".mybutton").prop('disabled', false);
Depending on whether you want it enabled/disabled it would be false/true.
This seemed to work for jquery ui buttons as well. What I was doing was checking a certain count and disabling the button when you first load the page.
But someone could change the count value by deleting something (via AJAX call):
//delete
jQuery(document).on("click", ".deletebutton", function() {
if (confirm("Are you sure you want to delete?"))
{
var hash = jQuery(this).data("delete");
var $this = jQuery(this);
jQuery.ajax({
url: "index.php?option=com_cam&task=delete&hash="+ hash +"&"+getToken()+"=1&format=raw",
dataType: 'json',
type: "POST",
success: function(data){
if (data.type == 'error')
{
//error message printed to user
}
else
{
$this.closest("tr").remove();
//deleted so decrement and check if you have exceeded your limit
count=count-1;
if (count >= limit)
{
//disable buttons
jQuery( ".mybutton" ).button( "option", "disabled", true );
}
else
{
//enable add buttons and hide message
jQuery( ".mybutton" ).button( "option", "disabled", false );
//jQuery(".mybutton").attr('disabled', false);
//jQuery(".mybutton").prop('disabled', false);
}
}
}
});
}
});
Then this should enable the button back again. Neither prop or attr or this post seemed to work for me. Only when I did this:
jQuery( ".mybutton" ).button( "option", "disabled", false );
I guess I don't understand why prop doesn't work in this context when it does work to disable my buttons? Is the best practice to always use the button setter?