Can't disable the button immediately after the reset.
Created by: f0t0n
This code is not working correctly:
var $btn = $('.btn-save');
$btn.button('reset');
$btn.attr('disabled', 'disabled'); // The button will not be disabled.
(Fiddle: http://jsfiddle.net/f0t0n/V2ZKY/)
The problem is the setTimeout
used in the Button.prototype.setState()
method:
https://github.com/twitter/bootstrap/blob/master/js/bootstrap-button.js#L46
So I'm forced to use a dirty workaround for this:
var $btn = $('.btn-save');
$btn.button('reset');
setTimetout(function() {
$btn.attr('disabled', 'disabled'); // Disables the button correctly.
}, 0);
(Fiddle: http://jsfiddle.net/f0t0n/BKXVA/)
Therefore It would be great if some event will be triggered from setTimeout
callback in
Button.prototype.setState()
to create an ability to catch the moment when the button can be disabled:
setTimeout(function () {
state == 'loadingText' ?
$el.addClass(d).attr(d, d) :
$el.removeClass(d).removeAttr(d);
// We can handle this event
// and perform any tasks we need inside the event handler:
$el.trigger('set:state:' + state);
}, 0);
Additionally it could be useful if allow user to pass an optional callback to the setState()
method.
So he don't need to observe events if he need to perform some action just once:
$btn.button('reset', function() {
$(this).attr('disabled', 'disabled');
});