Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • B bootstrap
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 263
    • Issues 263
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 114
    • Merge requests 114
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Bootstrap
  • bootstrap
  • Issues
  • #6242
Closed
Open
Issue created Dec 12, 2012 by Administrator@rootContributor

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');
});
Assignee
Assign to
Time tracking