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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...