Dashboards & Visualizations

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


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">
					<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;">
| 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" 




JS Used:-



], 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');
   // Iitialize Default and Submitted Token Model.
                var defaultTokenModel = mvc.Components.get("default");
        var submittedTokenModel = mvc.Components.get("submitted");

    var defaultTokenSpace = mvc.Components.getInstance('default');
                $('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;





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

Labels (2)
0 Karma


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

0 Karma
Register for .conf21 Now! Go Vegas or Go Virtual!

How will you .conf21? You decide! Go in-person in Las Vegas, 10/18-10/21, or go online with .conf21 Virtual, 10/19-10/20.