You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using clipboard.js: https://zenorocha.github.io/clipboard.js/ to allow users to copy things to clipboard. I need to be able to display a tooltip that says "copied" once the user clicks. Would anyone be able to walk me through how to do this? If it's even possible at all?
The code I'm using:
var clipboard = new Clipboard('.btn');
clipboard.on('success', function(e) {
console.log(e);
});
clipboard.on('error', function(e) {
console.log(e);
});
I assume that I'd need to use this: $(...).tooltipster('show', callback); but I'm not sure if placing that inside the above code or if that will even work at all?
Thank you for the very quick response! I haven't been using Tooltipster long and what I have done, hasn't been real extensive. Could you tell me what's new in V4 compared to 3?
And thanks for the Fiddle. I played around with your fiddle and am still running into the problem which I outlined above although hopefully now that I have a Fiddle to show you, maybe it's more clear (sorry... I'm a javascript noob so bear with me). Here's my update from your original Fiddle: http://jsfiddle.net/07frhLrd/4/
If you click on "Link1" for example, it works fine and copies, but then if you hover over "LInk2" then it also says "Copied" as the tooltip even though it in fact wasn't copied. So it's like I need a way to reset tooltips once someone clicks?
It would be too long to explain what's new (I'll do this soon in a dedicated post), but basically it works better in all kinds of way and adds lots of features for advanced users.
Your issue is that when you write .example_button, you're telling the Clipboard instance to work on all elements at the same time. So when an update happens on one of them, Clipboard calls the sucess callback on all elements and they all get their tooltips updated.
If clipboard was working the way it should, you could write just what I said and it would work : clipboard = new Clipboard(el). You can go on this page and give a +1 : zenorocha/clipboard.js#119
Until they fix it, just give an id to each button and write clipboard = new Clipboard('#' + $el.attr('id')). See http://jsfiddle.net/07frhLrd/5/
Ah, gosh. I should have known that. I actually had it partly correct messing around on my end but was glossing over the fact that I needed the '#' in there to indicate to look at the unique id. Sorry for my ignorance there.
I went and +1'd the clipboard.js issue so hopefully they'll get that fixed, but this solution will work for me. I'm not picky as long as it works. ;)
Again, I can't thank you enough for responding. Not often you get responses this fast and this in depth. Really helps a lot.
I noticed that you removed the data-copyerror tag from the code but you shouldn't, that's the message displayed in the tooltip when Clipboard.js cannot do its job.
I'm trying to use the Tooltipster + Clipboard.js combination for the opposite, i.e. I added a button to the tooltip and I want that the text in the tooltip is copied when I click on the button. But it doesn't work. Please see this fiddle. I'd approciate any help.
It would be too long to explain what's new (I'll do this soon in a dedicated post), but basically it works better in all kinds of way and adds lots of features for advanced users.
Your issue is that when you write .example_button, you're telling the Clipboard instance to work on all elements at the same time. So when an update happens on one of them, Clipboard calls the sucess callback on all elements and they all get their tooltips updated.
If clipboard was working the way it should, you could write just what I said and it would work : clipboard = new Clipboard(el). You can go on this page and give a +1 : zenorocha/clipboard.js#119
Until they fix it, just give an id to each button and write clipboard = new Clipboard('#' + $el.attr('id')). See http://jsfiddle.net/07frhLrd/5/
And you're welcome :)
Hi!
I am trying this and it is not working. Firefox throws error. It seems passing el is causing the issue. What can I do to make this work?
Activity
louisameline commentedon Nov 10, 2015
Hello!
This is a good opportunity to use Tooltipster v4 and its new features. Test URL here.
In the html:
In the javascript:
deronsizemore commentedon Nov 10, 2015
Thank you for the very quick response! I haven't been using Tooltipster long and what I have done, hasn't been real extensive. Could you tell me what's new in V4 compared to 3?
And thanks for the Fiddle. I played around with your fiddle and am still running into the problem which I outlined above although hopefully now that I have a Fiddle to show you, maybe it's more clear (sorry... I'm a javascript noob so bear with me). Here's my update from your original Fiddle: http://jsfiddle.net/07frhLrd/4/
If you click on "Link1" for example, it works fine and copies, but then if you hover over "LInk2" then it also says "Copied" as the tooltip even though it in fact wasn't copied. So it's like I need a way to reset tooltips once someone clicks?
Thanks again!
louisameline commentedon Nov 10, 2015
It would be too long to explain what's new (I'll do this soon in a dedicated post), but basically it works better in all kinds of way and adds lots of features for advanced users.
Your issue is that when you write
.example_button, you're telling the Clipboard instance to work on all elements at the same time. So when an update happens on one of them, Clipboard calls the sucess callback on all elements and they all get their tooltips updated.If clipboard was working the way it should, you could write just what I said and it would work :
clipboard = new Clipboard(el). You can go on this page and give a +1 : zenorocha/clipboard.js#119Until they fix it, just give an id to each button and write
clipboard = new Clipboard('#' + $el.attr('id')). See http://jsfiddle.net/07frhLrd/5/And you're welcome :)
deronsizemore commentedon Nov 10, 2015
Ah, gosh. I should have known that. I actually had it partly correct messing around on my end but was glossing over the fact that I needed the
'#'in there to indicate to look at the unique id. Sorry for my ignorance there.I went and +1'd the clipboard.js issue so hopefully they'll get that fixed, but this solution will work for me. I'm not picky as long as it works. ;)
Again, I can't thank you enough for responding. Not often you get responses this fast and this in depth. Really helps a lot.
louisameline commentedon Nov 10, 2015
I'm glad I could be of assistance !
I noticed that you removed the data-copyerror tag from the code but you shouldn't, that's the message displayed in the tooltip when Clipboard.js cannot do its job.
Good luck :)
deronsizemore commentedon Nov 10, 2015
Ok, thanks. I'll add that back definitely.
[-]Tooltipster with clipboard.js?[/-][+]Using Tooltipster with Clipboard.js[/+]azzimuth commentedon Jan 2, 2018
I'm trying to use the Tooltipster + Clipboard.js combination for the opposite, i.e. I added a button to the tooltip and I want that the text in the tooltip is copied when I click on the button. But it doesn't work. Please see this fiddle. I'd approciate any help.
kapooramit commentedon Jun 5, 2020
Hi!
I am trying this and it is not working. Firefox throws error. It seems passing el is causing the issue. What can I do to make this work?
kapooramit commentedon Jun 6, 2020
I get this error on using the recommended code:
Uncaught TypeError: Illegal constructor.