user3067524
user3067524

Reputation: 527

Bootstrap tabs pills disabling and with jQuery

I looked at the below example and am trying to add additional functionality. I would like to disable other two tables initially and when I submit the form from first tab and then enable second tab. I have tried using jQuery UO and jQuery. But not able to do with Bootstrap and jQuery.

jsFiddle Demo

Here is what I have tried so far.

$(document).ready(function() {
    $('#profile').attr('class', 'disabled');
    $('#message').attr('class', 'disabled');
    $('#profile').removeAttr('data-toggle');
    $('#messages').removeAttr('data-toggle');
});

Upvotes: 6

Views: 23213

Answers (2)

Dimitar Gospodinov
Dimitar Gospodinov

Reputation: 21

$(document).delegate('li.disabled a').on('click', function(e) { e.preventDefault(); return false; });

even if you dynamically add the 'disabled' class it will still work. cheers.

Upvotes: 0

melc
melc

Reputation: 11671

To disable the other two tabs and later on enable them on an event you can do the following,

http://jsfiddle.net/5zjXk/1/

js

$(document).ready(function() {
    /*disable non active tabs*/
    $('.nav li').not('.active').addClass('disabled');
/*to actually disable clicking the bootstrap tab, as noticed in comments by user3067524*/
    $('.nav li').not('.active').find('a').removeAttr("data-toggle");

    $('button').click(function(){
        /*enable next tab*/
        $('.nav li.active').next('li').removeClass('disabled');
        $('.nav li.active').next('li').find('a').attr("data-toggle","tab")
    });
});

html

<ul class="nav nav-pills">
  <li class="active"><a href="#home" data-toggle="tab">Home</a></li>
  <li><a href="#profile" data-toggle="tab">Profile</a></li>
  <li><a href="#messages" data-toggle="tab">Messages</a></li>
</ul>

    <div id='content' class="tab-content">
      <div class="tab-pane active" id="home">
        <ul>
            <li>home</li>
            <li>home</li>
            <li>home</li>
            <li>home</li>
        </ul>
          <button>submit</button>
      </div>
      <div class="tab-pane" id="profile">
        <ul>
            <li>profile</li>
            <li>profile</li>
            <li>profile</li>
            <li>profile</li>
            <li>profile</li>
        </ul>
          <button>submit</button>
      </div>
      <div class="tab-pane" id="messages">
          Tetsing
      </div>
    </div>    

Upvotes: 17

Related Questions