Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Guard AutocompleteInput against the create sentinel value

erwanMarmelabdc0c3a712f8a
diff --git a/src/components/admin/autocomplete-input.tsx b/src/components/admin/autocomplete-input.tsx
index 281f106b..3be80a31 100644
--- a/src/components/admin/autocomplete-input.tsx
+++ b/src/components/admin/autocomplete-input.tsx
@@ -170,14 +170,20 @@ export const AutocompleteInput = (
const handleChange = useCallback(
(choice: any) => {
- if (field.value === getChoiceValue(choice) && !isRequired) {
+ const value = getChoiceValue(choice);
+ // when onCreate returns nothing, ra-core hands back the create item itself:
+ // storing its sentinel value would leave an unrenderable value selected
+ if (value === (createValue ?? "@@ra-create")) {
+ return;
+ }
+ if (field.value === value && !isRequired) {
handleReset();
return;
}
- field.onChange(getChoiceValue(choice));
+ field.onChange(value);
setOpen(false);
},
- [field, getChoiceValue, isRequired, handleReset, setOpen],
+ [field, getChoiceValue, createValue, isRequired, handleReset, setOpen],
);
const {