Clipboard.js: [clipboardjs] Copy multiple target elements.

Created on 30 Sep 2016  路  5Comments  路  Source: zenorocha/clipboard.js

Is't possible coping multiple target elements?
Like, data-clipboard-target="#data-*"

Most helpful comment

You can't copy multiple target elements at once. But you can use the imperative API for that, for example:

new Clipboard('.btn', {
    text: function(trigger) {
        var a = document.querySelector('#a').value;
        var b = document.querySelector('#b').value;
        return a + b;
    }
});

All 5 comments

Make a test!

Simply it's not working.
Need a sample demo.

You can't copy multiple target elements at once. But you can use the imperative API for that, for example:

new Clipboard('.btn', {
    text: function(trigger) {
        var a = document.querySelector('#a').value;
        var b = document.querySelector('#b').value;
        return a + b;
    }
});

I modified what he did, in order to use in multiple places...
pasting here if somebody need:

new Clipboard('.btn-copy-mutiple', {
        text: function (trigger) {
            var targets = $(trigger).data('clipboard-targets');
            targets = targets.split(',');
            var copyString = '';
            var qtd = targets.length;
            for (var i = 0; i < qtd; i++) {
                copyString += ' ' + $(targets[i]).text();
            }
            return copyString;
        }
    });

button:

<a class="btn-copy-mutiple btn" data-clipboard-targets="#chamado-id27558,#chamado-titulo27558"><i class="fa fa-copy"></i></a>

ps:
.text() or val(), depending on what you're going to copy

I have generated a list of user emails (based on role) from WordPress. I'm trying to get a button on the page that will "copy all" emails. Thoughts on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

XZZsr picture XZZsr  路  5Comments

godoffrags picture godoffrags  路  4Comments

michael-letcher picture michael-letcher  路  3Comments

gunnarmorling picture gunnarmorling  路  6Comments

hassaanrana picture hassaanrana  路  6Comments