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

Text not copied to clipboard in disabled textarea #41

Closed
johnymontana opened this issue Sep 30, 2015 · 7 comments
Closed

Text not copied to clipboard in disabled textarea #41

johnymontana opened this issue Sep 30, 2015 · 7 comments

Comments

@johnymontana
Copy link

I am using clipboard.js to copy text from a disabled textarea (the text is programmatically generated and I don't want the user to edit it before copying):

<button class="copyBtn" data-clipboard-target="#myTextArea">Copy</button>
<textarea id="myTextArea" rows="10" disabled>My text here</textarea>

With the disabled property the text is not copied to the clipboard, despite the clipboard success event indicating that it is:

var clipboard = new Clipboard('.copyBtn');

        clipboard.on('success', function(e) {
            console.info('Action:', e.action);
            console.info('Text:', e.text);
            console.info('Trigger:', e.trigger);

            e.clearSelection();
        });

        clipboard.on('error', function(e) {
            console.error('Action:', e.action);
            console.error('Trigger:', e.trigger);
        });
Action: copy 
Text: My text here
Trigger: <button data-clipboard-target="#myTextArea" class="copyBtn">​

Removing the disabled property on the textarea, clipboard functions as expected and text is copied.

@zenorocha
Copy link
Owner

Have you tried readonly instead of disabled?

@johnymontana
Copy link
Author

Works fine with readonly, which makes more sense for my use-case. Thanks.

@zenorocha
Copy link
Owner

;D

@ngocdaothanh
Copy link

I encountered this problem too.
Clipboard.js works with disabled on Chrome, but not on Firefox.
readonly is OK on both.

I think you should update the readme and the web site to mention about readonly, as I think many people may encounter this problem too, and they may give up this wonderful Clipboard.js because they think it's broken.

@zenorocha zenorocha reopened this Jan 21, 2016
@LulzAugusto
Copy link

@ngocdaothanh is correct, disableddoesn't works on Firefox and yet it emits the success event.

@Damini25
Copy link

solution-
onCopy() {
const copyText = (document.getElementById('1'));
copyText.disabled = false;
copyText.select();
document.execCommand('Copy');
copyText.disabled = true;
}

@huy9x30
Copy link

huy9x30 commented May 24, 2019

@Damini25 your solution worked for me. Thanks a lot!

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

6 participants