VolkovLabs / business-text

The Business Text panel plugin allows you to construct a text visualization template from the values of a dataset returned by a data source query.
https://volkovlabs.io
Apache License 2.0
83 stars 13 forks source link

Javascript function not found #217

Closed craftzneko closed 1 year ago

craftzneko commented 1 year ago

Strange issue i have a dashboard where i call a function onclick and that works, i have a copy of that panel where i call a different function and it continually says function not found

HTML

  <div id="copyToClipboard" style="position: relative;">
    <i class="fas fa-copy" style="position: absolute; top: 0; right: 0; cursor: pointer; margin-top: 10px; margin-right: 10px;" onclick="copyToClipboard()"></i>
  </div>

JS

async function copyToClipboard() {
  var textToCopy = JSON.stringify(data, null, 2);
  try {
    await navigator.clipboard.writeText(textToCopy);
    console.log('Copying to clipboard was successful!');
    var icon = document.querySelector("#copyToClipboard .fa-copy");
    icon.classList.add("clicked");
    setTimeout(function () {
      icon.classList.remove("clicked");
    }, 1000); // remove the class after 1 second
  } catch (err) {
    console.error('Could not copy text: ', err);
  }
}

writing all loaded functions to console shows all the functions including previous ones but this one doesnt get added What am i doing wrong here?

craftzneko commented 1 year ago

Ok figured out i was using an arrow function in my previous panel, seems like function decleration doesnt work, so doing this, worked copyClip = async () => {}

mikhail-vl commented 1 year ago

@craftzneko Yes, arrow functions works.

Glad you was able to figure it out.