Skip to content

Commit 8bc8082

Browse files
Fix autocomplete in ReferenceInput (#673)
1 parent a7b4de7 commit 8bc8082

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

admin-js/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
"extends": [
1919
"react-app",
2020
"react-app/jest"
21-
]
21+
],
22+
"rules": {
23+
"react/jsx-pascal-case": [1, {"allowLeadingUnderscore": true}]
24+
}
2225
},
2326
"browserslist": {
2427
"production": [

admin-js/src/App.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@ import {
22
Admin, Create, Datagrid, Edit, EditButton, List, HttpError, Resource, SimpleForm,
33
BulkDeleteButton, BulkExportButton, BulkUpdateButton,
44
SimpleShowLayout, Show,
5+
AutocompleteInput,
56
BooleanField, BooleanInput,
67
DateField, DateInput,
78
NumberField, NumberInput,
8-
ReferenceField, ReferenceInput,
9+
ReferenceField, ReferenceInput as _ReferenceInput,
910
ReferenceManyField,
1011
SelectInput,
1112
TextField, TextInput,
1213
WithRecord, required
1314
} from "react-admin";
1415
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
1516

17+
/** Reconfigure ReferenceInput to filter by the displayed repr field. */
18+
const ReferenceInput = (props) => {
19+
const ref = props["reference"];
20+
const repr = STATE["resources"][ref]["repr"];
21+
return (
22+
<_ReferenceInput {...props}>
23+
<AutocompleteInput filterToQuery={s => ({[repr]: s})} />
24+
</_ReferenceInput>
25+
);
26+
};
27+
28+
1629
const _body = document.querySelector("body");
1730
const STATE = JSON.parse(_body.dataset.state);
1831
// Create a mapping of components, so we can reference them by name later.

0 commit comments

Comments
 (0)