Clipboard.js: programmed to work with hidden input?

Created on 2 Oct 2015  路  6Comments  路  Source: zenorocha/clipboard.js

Really like this - excellent work!
If i leave the input as it works as expected.
I'd like to use it with a hidden input, but when I add type="hidden" the text no longer gets copied.
Tried it with display:none but had the same results.
I can style the input so the input cannot be seen but I'd rather be able to use a hidden input, if possible.

question

Most helpful comment

If using an <input type="hidden"> is the only option, then you could go with:

new Clipboard('.btn', {
    text: function() {
        return document.querySelector('input[type=hidden]').value;
    }
});

All 6 comments

Hey @168tickets,

You can either use the readonly attribute on your input or the data-clipboard-text option.

If using an <input type="hidden"> is the only option, then you could go with:

new Clipboard('.btn', {
    text: function() {
        return document.querySelector('input[type=hidden]').value;
    }
});

Hope that helps @168tickets, thanks!

Sure did! I used data-clipboard-text option so I didn't need the hidden input. Works great! Thanks so much!

I can't seem to get this to work with <input type="hidden" readonly="true" id="inputID" data-clipboard-text="VALUE.">.

Hey,
same problem here, can't make it work with hidden :(((
Finally used : data-clipboard-text="'.$url.'"
works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zenorocha picture zenorocha  路  5Comments

XZZsr picture XZZsr  路  5Comments

toolaugh picture toolaugh  路  5Comments

flydev-fr picture flydev-fr  路  3Comments

godoffrags picture godoffrags  路  4Comments