Skip to content

Commit

Permalink
🐛 [#4606] Fix default react-select behaviour when clearing the value
Browse files Browse the repository at this point in the history
react-select sets the value to null, which doesn't have a property
'value', leading to crashes. Instead, we set the formik field value
to 'undefined', which effectively clears it in the formik state.
  • Loading branch information
sergei-maertens committed Aug 19, 2024
1 parent 5295cd6 commit d488b1c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/openforms/js/components/admin/forms/ReactSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ const Select = ({name, options, ...props}) => {
{...fieldProps}
value={options.find(opt => opt.value === value) || null}
onChange={selectedOption => {
setValue(selectedOption.value);
// clear the value
if (selectedOption == null) {
setValue(undefined);
} else {
setValue(selectedOption.value);
}
}}
{...props}
/>
Expand Down

0 comments on commit d488b1c

Please sign in to comment.