Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy failing when text is null #154

Closed
Nothing4You opened this issue Dec 18, 2015 · 4 comments
Closed

Copy failing when text is null #154

Nothing4You opened this issue Dec 18, 2015 · 4 comments

Comments

@Nothing4You
Copy link

Hey there,

suppose I have the following code:

<button id="copy-link" onclick="return false;">Copy link</button>

with

var clipboard;
var clipboardText = null;;
clipboard = new Clipboard('button#copy-link', {
    text: function() {
        return clipboardText;
    }
});
clipboard.on('success', function(e) {
    // success animation
});
clipboard.on('error', function(e) {
    // Custom error-catching prompt wrapper
    tryPrompt("You can copy the link with Control+C", clipboardText);
});

The content of clipboardText is dynamically set depending on what is currently needed.
Sometimes there is no link available, in which case I want to inform the user about that and run some other js stuff, prompting the user to provide a link.
However, due to the current check for text being set, when I return null it checks the same way as it would for undefined or even an empty string.
Is there currently any way to implement this feature?

@loter
Copy link

loter commented Feb 23, 2016

just make it
return clipboardText || ' ';

You can find similar bug report in closed bugs
#148

@Nothing4You
Copy link
Author

As the comment in the other issue already tells, I'd rather not copy an empty string if there is null, since clearing the clipboard isn't what I'm looking for there.

@zenorocha
Copy link
Owner

Fixed at 7a5a910. Please use v1.5.10 in order to benefit from this.

@Nothing4You
Copy link
Author

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants