Dashboards & Visualizations

How to copy text and tokens values getting populated inside textarea to the clipboard while clicking on copy button ?

tarunmalhotra79
Engager

Hi Splunkers,

I am trying to copy the whole text inside textarea to the clipboard when user clicks on a button. I tried implementing suggestions from stackoverflow but nothing worked.

It looks like may be i have hardcoded some text and also using run time token which might be causing issues.

 

 

 

<panel id="Os_details">
      <html>
				<div>
					<label>Paste the following in your alerting search</label>
					<button id="clipboard">Copy to Clipboard</button>
					<textarea name="generateSearchWindow" rows="25" readonly="true" style="width:98%;margin-top:12px;color:black; text-align: left;">
$MainSearch$
| eval p_os = "$os_change_tok$"
| eval p_alert_class = "$alert_class_change_tok$" 
| eval p_monitoring_type = "$monitoring_type_change_tok$"
| eval p_monitoring_component = $monitoringComponent$
| eval p_hostname = "$hostnamePattern$" 
| eval search_name = "$searchName$" 
| eval unique_id=p_os + ":" + p_alert_class + ":" + p_monitoring_type + ":" + p_monitoring_component + ":" + p_hostname  
| fields - _raw
| collect index=Test_monitoring_test addtime=false report_name="Test_EE_$searchName$_default" 
          </textarea>
				</div>
			</html>
    </panel>
  </row>
  <row>
    <panel>

 

 

 

JS Used:-

 

 

  'underscore',
  'jquery',
  'backbone',
  'splunkjs/mvc',
  'splunkjs/mvc/searchmanager',
  'splunkjs/mvc/simplexml/ready!'
], function(_, $, Backbone, mvc,SearchManager) {
  //Find your input control and associate tool tip attribute for it. Here data-placement represents the position of tool tip(top,bottom,right,left,auto)
  $('#textbox1').find('input').attr('title', 'Hovering Example to be added').attr('data-toggle', 'tooltip').attr('data-placement', 'bottom');
  $('#monitoringComponent').find('div').attr('title', 'TextArea example').attr('data-toggle', 'tooltip').attr('data-placement', 'bottom');
  $('[data-toggle="tooltip"]').tooltip();
   // Iitialize Default and Submitted Token Model.
                var defaultTokenModel = mvc.Components.get("default");
        var submittedTokenModel = mvc.Components.get("submitted");
        $("#ValidateButton").click(function()
                {
            defaultTokenModel.set("show_details","true");
            submittedTokenModel.set("show_details","true");
        });

    var defaultTokenSpace = mvc.Components.getInstance('default');
                $('textarea').parent().parent().addClass('textarea_div');
                $('textarea').each(function (ta) {
                $(this).on('input', function(input) {
                defaultTokenSpace.set($(this).attr('id').replace('ta_' ,'') ,$(this).val());
    });
  });
   document.getElementById("clipboard").onclick = function() {
  var copyTextarea = document.createElement("textarea");
  copyTextarea.style.position = "fixed";
  copyTextarea.style.opacity = "0";
  copyTextarea.textContent = document.getElementById("generateSearchWindow").value;

  document.body.appendChild(copyTextarea);
  copyTextarea.select();
  document.execCommand("copy");
  document.body.removeChild(copyTextarea);
}

});

 

 

Kindly help me, what am I missing please or where should i focus more. It would be highly appreciated.

Labels (2)
0 Karma

tarunmalhotra79
Engager

Can someone please help me around here. That would be highly appreciable.

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...