diff --git a/packages/form-js-editor/src/features/properties-panel/entries/JSFunctionEntry.js b/packages/form-js-editor/src/features/properties-panel/entries/JSFunctionEntry.js index 189a220de..86f13fd87 100644 --- a/packages/form-js-editor/src/features/properties-panel/entries/JSFunctionEntry.js +++ b/packages/form-js-editor/src/features/properties-panel/entries/JSFunctionEntry.js @@ -107,14 +107,30 @@ function FunctionDefinition(props) { return get(field, path, ''); }; - const setValue = (value) => { + const setValue = (value, error) => { + if (error) { + return; + } + return editField(field, path, value || ''); }; + const validate = (value) => { + + try { + new Function(value); + } catch (e) { + return `Invalid syntax: ${e.message}`; + } + + return null; + }; + return TextAreaEntry({ debounce, element: field, getValue, + validate, description: 'Define the javascript function to execute.\nAccess the `data` object and use `setValue` to update the form state.', id, label: 'Javascript code',