VolkovLabs / business-forms

The Business Forms panel is a conceptually new plugin for Grafana. It is the first plugin that allows inserting and updating application data, as well as modifying configuration directly from your Grafana dashboard.
https://docs.volkovlabs.io
Apache License 2.0
86 stars 10 forks source link

elements is not defined #362

Closed craftzneko closed 8 months ago

craftzneko commented 8 months ago

Trying to dynamically change a form based on selected options in a form. So if a user selects an option it can hide form elements. Using this code in "element value changed" section


/**
 * Find Search and AssetName elements
 */
const searchElement = elements.find((element) => element.id === "Search");
const assetNameElement = elements.find((element) => element.id === "AssetName");

if (searchElement && assetNameElement) {
  // If the Search's value is 'single', unhide the AssetName element
  // If it's 'multi', hide the AssetName element
  assetNameElement.hidden = searchElement.value !== 'single';
}

/**
 * Update Panel Options
 */
onOptionsChange({ ...options, elements });

generate this error

reportUnhandledError.js:10 Uncaught ReferenceError: elements is not defined at eval (eval at (module.js:1:1), :7:23) at eval (FormPanel.tsx:759:7) at Object.eval [as next] (FormPanel.tsx:812:7) at L.next (Subscriber.js:96:33) at W._next (Subscriber.js:63:26) at W.next (Subscriber.js:34:18) at l (EventBus.ts:38:18) at l.emit (index.js:181:35) at s.publish (EventBus.ts:28:18) at eval (useFormElements.ts:78:26)

I am using elements which i thought was defined by the plugin already inside update section and it works fine

craftzneko commented 8 months ago

Realised i had to use context.panel.elements in "element value changed" whereas just need to do element in the other areas