Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't disable the button immediately after the reset. #6242

Closed
f0t0n opened this issue Dec 12, 2012 · 7 comments
Closed

Can't disable the button immediately after the reset. #6242

f0t0n opened this issue Dec 12, 2012 · 7 comments
Labels

Comments

@f0t0n
Copy link

f0t0n commented Dec 12, 2012

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');
});
@AydinHassan
Copy link

I'm having the same issue. @f0t0n's solution fixes the problem however it would be nice to see this fixed.

@mnapoli
Copy link

mnapoli commented Feb 4, 2013

argh how weird, I thought I was becoming crazy, thanks for the workaround. I changed it to using prop() for jQuery 1.6+:

setTimetout(function() {
    $(".inputSave").prop("disabled", true);
}, 0);

A fix would be great indeed.

@fat
Copy link
Member

fat commented Feb 8, 2013

if you open a pull request which adds an event i'd be happy to merge it

@fat fat closed this as completed Feb 8, 2013
@mnapoli
Copy link

mnapoli commented Feb 8, 2013

@fat Closing a bug report because it needs a fix, it's a weird way to go. It's like saying: there is no bug, unless you can fix it. This is an issue tracker, it's OK to have open issues. Nobody is demanding that you fix them yourself, having an open bug means other people (that are competent enough) can create a PR.

@lachi87
Copy link

lachi87 commented Dec 1, 2014

We are using Bootstrap latest version(3.3.1) and still we are facing this issue. Is this issue not yet fixed?

@yahermann
Copy link

Bootstrap 3.3.2 has the same issue. This is NOT CLOSED. It's not just disabling the button, it appears any jQuery method applied to the button after the .button('reset'). For example:

btn.button('reset');
btn.find('.something').addClass('someclass'); // WILL NOT WORK

Workaround:
btn.button('reset');
setTimeout(function() {
btn.find('.something').addClass('someclass'); // will work, but it's UGLY!
}, 0);

@hnrch02
Copy link
Collaborator

hnrch02 commented Feb 26, 2015

@yahermann That's happening because of #14450.

@twbs twbs locked and limited conversation to collaborators Feb 26, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants