{"record":{"id":"9bdd27db642ec511","repo":"marmelab/react-admin","slug":"emptyvalue-being-set-to-null-or-undefined-is-not-s","errorCode":null,"errorMessage":"emptyValue being set to null or undefined is not supported. Use parse to turn the empty string into null.","messagePattern":"emptyValue being set to null or undefined is not supported\\. Use parse to turn the empty string into null\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/input/AutocompleteInput.tsx","lineNumber":288,"sourceCode":"            translate,\n        ]\n    );\n\n    const selectedChoice = useSelectedChoice<\n        OptionType,\n        Multiple,\n        DisableClearable,\n        SupportCreate\n    >(field.value, {\n        choices: finalChoices,\n        // @ts-ignore\n        multiple,\n        optionValue,\n    });\n\n    useEffect(() => {\n        if (emptyValue == null) {\n            throw new Error(\n                `emptyValue being set to null or undefined is not supported. Use parse to turn the empty string into null.`\n            );\n        }\n    }, [emptyValue]);\n\n    useEffect(() => {\n        // eslint-disable-next-line eqeqeq\n        if (isValidElement(optionText) && emptyText != undefined) {\n            throw new Error(\n                `optionText of type React element is not supported when setting emptyText`\n            );\n        }\n        // eslint-disable-next-line eqeqeq\n        if (isValidElement(optionText) && inputText == undefined) {\n            throw new Error(`\nIf you provided a React element for the optionText prop, you must also provide the inputText prop (used for the text input)`);\n        }\n        if (","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/input/AutocompleteInput.tsx#L270-L306","documentation":"<AutocompleteInput> uses a sentinel empty value to represent 'no selection'; setting `emptyValue` to null or undefined breaks that sentinel logic (an undefined/null emptyValue cannot be distinguished from real option values). The library forbids it and asks you to convert the empty input string to null/undefined via `parse` instead.","triggerScenarios":"Passing `emptyValue={null}` or an emptyValue variable that evaluates to null/undefined (e.g. from a constant or config that is unset) to <AutocompleteInput>; the useEffect check runs after render.","commonSituations":"Trying to store null in the form when the input is cleared; wiring emptyValue from a settings object that is missing; copying examples where emptyValue defaults to '' and overriding it badly.","solutions":["Remove the emptyValue prop (the default '' works).","If you need null stored on clear, keep emptyValue='' and add `parse={value => (value === '' ? null : value)}`.","Ensure whatever feeds emptyValue is always a non-null string (e.g. `emptyValue={cfg.emptyValue ?? ''}`)."],"exampleFix":"// before\n<AutocompleteInput source=\"category\" emptyValue={null} />\n\n// after\n<AutocompleteInput\n  source=\"category\"\n  parse={value => (value === '' ? null : value)}\n/>","handlingStrategy":"validation","validationCode":"if (emptyValue == null) throw new Error('emptyValue must be a non-null string; use parse for null on clear');","typeGuard":"const hasValidEmptyValue = (p: { emptyValue?: unknown }): p is { emptyValue: string | number | boolean } => p.emptyValue != null;","tryCatchPattern":null,"preventionTips":["Omit emptyValue unless you specifically need a custom sentinel; default is ''.","Use parse={v => v === '' ? null : v} to store null on clear instead of emptyValue={null}.","Coalesce config-derived values: emptyValue={cfg.emptyValue ?? ''}."],"tags":["react-admin","autocompleteinput","invalid-props","forms"],"backgroundTag":"invalid-prop-value","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}