VolkovLabs/volkovlabs-form-panel

elements is not defined

craftzneko opened this issue · 1 comments

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

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