Skip to content

Commit

Permalink
chore: js syntax validation in properties panel
Browse files Browse the repository at this point in the history
Related to #1102
  • Loading branch information
Skaiir committed Apr 2, 2024
1 parent e4a0fa2 commit 7d43c96
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 7d43c96

Please sign in to comment.