Skip to content

Commit

Permalink
🐛 [#4908] Add copy of formVariables to the JSON variable configuratio…
Browse files Browse the repository at this point in the history
…n editor

The field 'formVariables' is read-only, so need an extra const to modify its value. Note, this didn't show up in storybook testing, only in manual functional testing
  • Loading branch information
viktorvanwijk committed Jan 2, 2025
1 parent 01f8e1e commit 6492749
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {Checkbox} from 'components/admin/forms/Inputs';


const JSONVariableConfigurationEditor = ({variable}) => {
const [fieldProps, , fieldHelpers] = useField('formVariables');
const {setValue} = fieldHelpers;
const [fieldProps, , {setValue}] = useField('formVariables');

const formVariables = fieldProps.value
const isIncluded = formVariables.includes(variable.key);
Expand All @@ -34,21 +33,22 @@ const JSONVariableConfigurationEditor = ({variable}) => {
}
checked={isIncluded}
onChange={event => {
const index = formVariables.indexOf(variable.key);
const formVariablesNew = formVariables.slice()
const index = formVariablesNew.indexOf(variable.key);
if (event.target.checked) {
if (index !== -1) {throw new Error(
"This form variable is already on the list of " +
"form variables to include. This shouldn't happen."
);}
formVariables.push(variable.key);
formVariablesNew.push(variable.key);
} else {
if (index === -1) {throw new Error(
"This form variable is not yet on the list of " +
"form variables to include. This shouldn't happen."
);}
formVariables.splice(index, 1);
formVariablesNew.splice(index, 1);
}
setValue(formVariables);
setValue(formVariablesNew);
}}
/>
</Field>
Expand Down

0 comments on commit 6492749

Please sign in to comment.