I need to display a tooltip on disabled button and remove it on enabled button. Actually it works in reverse way.
What is the best way to invert this behaviour?
$('[rel=tooltip]').tooltip();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<hr>
<button class="btn" disabled rel="tooltip" data-title="Dieser Link führt zu Google">button disabled</button>
<button class="btn" rel="tooltip" data-title="Dieser Link führt zu Google">button not disabled</button>
Here is the demo: http://jsfiddle.net/BA4zM/68/
P.S.: I want to keep the attribute disabled.
You can simply override Bootstrap's "pointer-events" style for disabled buttons via CSS e.g.
Better still be explicit and disable specific buttons e.g.
pointer-events: auto;
does not work on an<input type="text" />
.I took a different approach. I do not disable the input field, but make it act as disabled via css and javascript.
Because the input field is not disabled, the tooltip is displayed properly. It was in my case way simpler than adding a wrapper in case the input field was disabled.
Working code for Bootstrap 3.3.6
Javascript:
CSS:
This is what myself and tekromancr came up with.
Example element:
note: the tooltip attributes can be added to a separate div, in which the id of that div is to be used when calling .tooltip('destroy'); or .tooltip();
this enables the tooltip, put it in any javascript that is included in the html file. this line might not be necessary to add, however. (if the tooltip shows w/o this line then don't bother including it)
destroys tooltip, see below for usage.
prevents the button from being clickable. because the disabled attribute is not being used, this is necessary, otherwise the button would still be clickable even though it "looks" as if it is disabled.
Using bootstrap, the classes btn and btn-disabled are available to you. Override these in your own .css file. you can add any colors or whatever you want the button to look like when disabled. Make sure you keep the cursor: default; you can also change what .btn.btn-success looks like.
add the code below to whatever javascript is controlling the button becoming enabled.
tooltip should now only show when the button is disabled.
if you are using angularjs i also have a solution for that, if desired.
You can imitate the effect using CSS3.
Simply take the disabled state off the button and the tooltip doesn't appear anymore.. this is great for validation as the code requires less logic.
I wrote this pen to illustrate.
CSS3 Disabled Tooltips
You can wrap the disabled button and put the tooltip on the wrapper:
If the wrapper has
display:inline
then the tooltip doesn't seem to work. Usingdisplay:block
anddisplay:inline-block
seem to work fine. It also appears to work fine with a floated wrapper.UPDATE Here's an updated JSFiddle that works with the latest Bootstrap (3.3.6). Thanks to @JohnLehmann for suggesting
pointer-events: none;
for the disabled button.http://jsfiddle.net/cSSUA/209/