When I try to display a new tooltip, after destroying the old one, I get "Uncaught TypeError: Cannot read property 'trigger' of null" in the Chrome Console.
Then, when I was digging in the bootstrap code, I found this:
And I suspect that is responsible for the exception I'm getting:
I've tried using the "selector" and "container" attributes when creating the new tooltip. One thing that worked was adding an event listener on another button, to destroy the tooltip, that way when I click register again, it works properly and no exceptions are thrown.
The example can be found at (click register twice): https://jsfiddle.net/08o4qgj5/1/ Code:
$("form#register").on("click", "button[name='btnRegister']", function () {
//Destroy tooltip if exists
$("input[name='email']").tooltip('destroy');
//Adds new one
$("input[name='email']").tooltip({title: "CYKA BLYAAAAAAT, IDI NAHUI!",
placement: 'bottom',
template:'<div class="tooltip" role="tooltip">' +
'<div class="tooltip-arrow"></div>' +
'<div class="tooltip-inner"></div>' +
'</div>'});
//Shows it
$("input[name='email']").tooltip('show');
});
$("form#register").on("click", "button[name='btnDestroy']", function () {
//Destroys tooltip
$("input[name='email']").tooltip('destroy');
});
In the example I shown you, it's a bit useless to do this because there's only 1 input. But on my website, what I want to happen is:
- Destroy any tooltip that might exist
- Validate the user input
- In case the input is invalid, I want to add a new tooltip to that input element
The most similar problem I've found someone having is: Bootstrap 3 Tooltip flickers but that didn't solve it for me.
Thanks in advance.