{"record":{"id":"f04d6d7c2c8e3bcb","repo":"marmelab/react-admin","slug":"if-you-re-not-wrapping-the-selectinput-inside-a-re","errorCode":null,"errorMessage":"If you're not wrapping the SelectInput inside a ReferenceInput, you must provide the source prop","messagePattern":"If you're not wrapping the SelectInput inside a ReferenceInput, you must provide the source prop","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ra-ui-materialui/src/input/SelectInput.tsx","lineNumber":175,"sourceCode":"\n    const {\n        allChoices,\n        isPending,\n        error: fetchError,\n        source,\n        resource,\n        isFromReference,\n    } = useChoicesContext({\n        choices: choicesProp,\n        isLoading: isLoadingProp,\n        isFetching: isFetchingProp,\n        isPending: isPendingProp,\n        resource: resourceProp,\n        source: sourceProp,\n    });\n\n    if (source === undefined) {\n        throw new Error(\n            `If you're not wrapping the SelectInput inside a ReferenceInput, you must provide the source prop`\n        );\n    }\n\n    if (!isPending && !fetchError && allChoices === undefined) {\n        throw new Error(\n            `If you're not wrapping the SelectInput inside a ReferenceInput, you must provide the choices prop`\n        );\n    }\n\n    const getRecordRepresentation = useGetRecordRepresentation(resource);\n    const { getChoiceText, getChoiceValue, getDisableValue } = useChoices({\n        optionText:\n            optionText ??\n            (isFromReference ? getRecordRepresentation : undefined),\n        optionValue,\n        disableValue,\n        translateChoice: translateChoice ?? !isFromReference,","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-ui-materialui/src/input/SelectInput.tsx#L157-L193","documentation":"SelectInput resolves its choices via useChoicesContext, which works either standalone (with an explicit `source` and `choices`) or inside a ReferenceInput (which supplies context). When the component is not inside a ReferenceInput-providing context and `source` is undefined, it cannot bind to the form field, so it throws.","triggerScenarios":"Rendering a bare <SelectInput choices={...} /> with no source prop outside a ReferenceInput; destructuring/forgetting source in a custom wrapper that spreads props; using SelectInput inside a context that doesn't supply a record source.","commonSituations":"Building custom wrappers that accidentally drop the source prop; moving a SelectInput out of a ReferenceInput but forgetting it still relied on context; dynamic forms where source is computed and can be undefined.","solutions":["Add the source prop: <SelectInput source=\"status\" choices={...} />.","Or wrap it in <ReferenceInput source=\"...\" reference=\"...\"> so the context supplies the source.","In custom wrappers, pass through the source prop explicitly and guard it before render."],"exampleFix":"// before\n<SelectInput choices={[{ id: 'a', name: 'A' }]} />\n\n// after\n<SelectInput source=\"status\" choices={[{ id: 'a', name: 'A' }]} />","handlingStrategy":"validation","validationCode":"if (!source) {\n  throw new Error('SelectInput outside a ReferenceInput requires a source prop');\n}","typeGuard":"const hasSource = (p: { source?: string }): p is { source: string } =>\n  typeof p.source === 'string' && p.source.length > 0;","tryCatchPattern":null,"preventionTips":["Always pass source to standalone SelectInput","When wrapping SelectInput, forward source explicitly instead of relying on spreads","Prefer wrapping in ReferenceInput when choices come from a related resource"],"tags":["react-admin","select-input","props","required-prop"],"backgroundTag":"missing-required-prop","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}