Reputation: 81
I am using bootsrap tabs for a registration form , I changed navigation of tabs using onclick event of next and previous button . But still that tabs click works and being able to go the desired page easily Please help how can i stop tab click navigation i only want next previous button navigation Please find the html code below
<ul class="nav nav-tabs" id="myTab">
<li class="active">
<a href="#home" data-toggle="tab">1.PERSONAL DETAILS</a>
</li>
<li>
<a href="#profile" data-toggle="tab"> 2. CONTACT DETAILS</a>
</li>
<li>
<a href="#messages" data-toggle="tab">3. EDUCATION DETAILS</a>
</li>
<li>
<a href="#course" data-toggle="tab">4. SELECT COURSE</a>
</li>
<li>
<a href="#settings" data-toggle="tab">5. PAYMENT DETAILS</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">Form elements </div>
<div id="profile">Form elements </div>
<div id="messages">Form elements </div>
<div id="settings">Form elements </div>
</div>
Upvotes: 5
Views: 51025
Reputation: 53
I had this problem for a while.
Remove the data-toggle
to do conditionally by Javascript
Give tabs ids in the <a>
tag
document.getElementById(tabId)[0].setAttribute("data-toggle", "");
Upvotes: 0
Reputation: 1320
I used
style="pointer-events: none;"
something like:
<div class="steps nav" role="tablist">
<div href="#first" data-toggle="tab" role="tab" class="step mb-4 active" style="pointer-events: none;">
<div class="number">1</div>
first
</div>
<div href="#second" data-toggle="tab" role="tab" class="step mb-4" style="pointer-events: none;">
<div class="number">2</div>
second
</div>
</div>
seems to be doing the trick. still able to perform navigation using .click() function. which is what most are looking for.
something like
$('.nav [href="' + target + '"]').click()
Happy coding!
Upvotes: 1
Reputation: 2321
I tried all suggested answers, but finally i made it work like this
if (AnyCondition) //your condition
{
$("a[data-toggle='tab'").prop('disabled', true);
$("a[data-toggle='tab'").each(function () {
$(this).prop('data-href', $(this).attr('href')); // hold you original href
$(this).attr('href', '#'); // clear href
});
$("a[data-toggle='tab'").addClass('disabled-link');
}
else
{
$("a[data-toggle='tab'").prop('disabled', false);
$("a[data-toggle='tab'").each(function () {
$(this).attr('href', $(this).prop('data-href')); // restore original href
});
$("a[data-toggle='tab'").removeClass('disabled-link');
}
// if you want to show extra messages that the tab is disabled for a reason
$("a[data-toggle='tab'").click(function(){
alert('Tab is disabled for a reason');
});
Upvotes: -2
Reputation: 51
Use following code to disable the user Click on tab:
$('li:has([data-toggle="tab"])').click(function(event){return false;});
Maker sure this code will be added after your bootsrtap js
Upvotes: 0
Reputation: 71
I was having the same issue and this is what i used.
$("element").click(event) {
event.stopImmediatePropagation();
}
you just intercept the click event and then kill the event. To show the tabs, I'd just use $(tab.content).fadeIn();
Upvotes: 7
Reputation: 2381
$(document).ready(function(){
$("#tabs > li").click(function(){
if($(this).hasClass("disabled"))
return false;
});
});
It will be enough to work
Upvotes: 1
Reputation: 5573
I have tabs like this in the HTML (using Bootstrap 3.0):
<ul class="nav nav-tabs" id="createNotTab">
<li class="active" ><a href="#home" data-toggle="tab">Step 1: Select Property</a></li>
<li class="disabled"><a href="#createnotification" data-toggle="" >Step 2: Create Notification</a></li>
</ul>
Next/Previous buttons
<button class="btn btn-warning prevtab" type="button" onclick="return showPrev()"><span class="glyphicon glyphicon-arrow-left"></span>Previous </button>
<button class="btn btn-info prevtab" type="button" onclick="return showNext()"><span class="glyphicon glyphicon-arrow-right"></span>Next </button>
In my JavaScript file:
var $tabs = $('#createNotTab li');
function showPrev() {
$tabs.filter('.active').prev('li').removeClass("disabled");
$tabs.filter('.active').prev('li').find('a[data-toggle]').each(function () {
$(this).attr("data-toggle", "tab");
});
$tabs.filter('.active').prev('li').find('a[data-toggle="tab"]').tab('show');
$tabs.filter('.active').next('li').find('a[data-toggle="tab"]').each(function () {
$(this).attr("data-toggle", "").parent('li').addClass("disabled");
})
}
function showNext() {
$tabs.filter('.active').next('li').removeClass("disabled");
$tabs.filter('.active').next('li').find('a[data-toggle]').each(function () {
$(this).attr("data-toggle", "tab");
});
$tabs.filter('.active').next('li').find('a[data-toggle="tab"]').tab('show');
$tabs.filter('.active').prev('li').find('a[data-toggle="tab"]').each(function () {
$(this).attr("data-toggle", "").parent('li').addClass("disabled");;
})
}
If you are having multiple tabs, set class="disabled"
and data-toggle=""
for all the li items that you want to deactivate.
Upvotes: 8
Reputation: 123
Super simple...
Add disabled class to tab li. on show.bs.tab event attached to a[data-toggle='tab'] element check to see if its parent has the disabled class... if so return false...
Upvotes: 1
Reputation: 902
try this for disabling a tab
$('#tab').attr('class', 'disabled');
$('tab').click(function(event){
if ($(this).hasClass('disabled')) {
return false;
}
});
Upvotes: 6