Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Muultiple elements on same page in rails? #36

Open
msumeet opened this issue Oct 6, 2015 · 1 comment
Open

Muultiple elements on same page in rails? #36

msumeet opened this issue Oct 6, 2015 · 1 comment

Comments

@msumeet
Copy link

msumeet commented Oct 6, 2015

I have 10 elements on one page in each do loop that should allow user to copy when someone clicks on button. I managed to add copy to clipboard functionality to rails using Zeroclipboard-rails gem. As I have multiple items on same page I have changed Id to Class.

$(document).ready(function() {
    var clip = new ZeroClipboard($("#d_clip_button"))
  });
$(document).ready(function() {
    var clip = new ZeroClipboard($(".class_name"))
  });

But whenever I click on copy to clipboard button on any of 10 elements It selects the value of first item. How can I Fix This?

Here is the complete code. Thanks.

  <button class='my_clip_button' data-clipboard-target='fe_text' data-clipboard-text='Default clipboard     text from attribute' id='d_clip_button' title='Click me to copy to clipboard.'>
<script>
  $(document).ready(function() {
    var clip = new ZeroClipboard($(".my_clip_button"));

  $("#d-clip_button").on("click", function(){
    $("#fe_text").val("Copy me!");
  });
</script>
@JamesMGreene
Copy link
Member

The code you've shown doesn't really correlate with your description of the scenario. For example, you said you have 10 clipped buttons but you've only shown the HTML for 1 of them.

Also, what is the intent of your "click" handler? It's very unclear to me.

Last but not least, this wouldn't be anything specific to the "zeroclipboard-rails" Gem, so ideally you should raise this question on the core ZeroClipboard repo instead.

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

No branches or pull requests

2 participants