diff --git a/src/pages/city/create.tsx b/src/pages/city/create.tsx index 09bdd63..2d54797 100644 --- a/src/pages/city/create.tsx +++ b/src/pages/city/create.tsx @@ -16,6 +16,17 @@ export const CityCreate = () => { resource: 'country', }) + const {autocompleteProps: mediaAutocompleteProps} = useAutocomplete({ + resource: 'media', + onSearch: (value) => [ + { + field: 'filename', + operator: 'contains', + value, + }, + ], + }) + return ( @@ -32,12 +43,12 @@ export const CityCreate = () => { field.onChange(value?.code || '') }} getOptionLabel={(item) => { - return item ? item.code : '' + return item ? item.name : '' }} isOptionEqualToValue={(option, value) => { return option.id === value?.id }} - renderInput={(params) => } + renderInput={(params) => } /> )} /> @@ -55,6 +66,32 @@ export const CityCreate = () => { label={'Название'} name="name" /> + + ( + option.id === field.value) || null} + onChange={(_, value) => { + field.onChange(value?.id || '') + }} + getOptionLabel={(item) => { + return item ? item.filename : '' + }} + isOptionEqualToValue={(option, value) => { + return option.id === value?.id + }} + filterOptions={(options, {inputValue}) => { + return options.filter((option) => option.filename.toLowerCase().includes(inputValue.toLowerCase())) + }} + renderInput={(params) => } + /> + )} + /> ) diff --git a/src/pages/city/edit.tsx b/src/pages/city/edit.tsx index d9c7769..9e2ec55 100644 --- a/src/pages/city/edit.tsx +++ b/src/pages/city/edit.tsx @@ -15,6 +15,17 @@ export const CityEdit = () => { resource: 'country', }) + const {autocompleteProps: mediaAutocompleteProps} = useAutocomplete({ + resource: 'media', + onSearch: (value) => [ + { + field: 'filename', + operator: 'contains', + value, + }, + ], + }) + return ( @@ -31,12 +42,12 @@ export const CityEdit = () => { field.onChange(value?.code || '') }} getOptionLabel={(item) => { - return item ? item.code : '' + return item ? item.name : '' }} isOptionEqualToValue={(option, value) => { return option.id === value?.id }} - renderInput={(params) => } + renderInput={(params) => } /> )} /> @@ -54,6 +65,32 @@ export const CityEdit = () => { label={'Название'} name="name" /> + + ( + option.id === field.value) || null} + onChange={(_, value) => { + field.onChange(value?.id || '') + }} + getOptionLabel={(item) => { + return item ? item.filename : '' + }} + isOptionEqualToValue={(option, value) => { + return option.id === value?.id + }} + filterOptions={(options, {inputValue}) => { + return options.filter((option) => option.filename.toLowerCase().includes(inputValue.toLowerCase())) + }} + renderInput={(params) => } + /> + )} + /> ) diff --git a/src/pages/city/show.tsx b/src/pages/city/show.tsx index 54777be..1672100 100644 --- a/src/pages/city/show.tsx +++ b/src/pages/city/show.tsx @@ -13,17 +13,19 @@ export const CityShow = () => { {label: 'Название', data: 'name'}, // {label: 'Код страны', data: 'country_code'}, {label: 'Страна', data: 'country'}, + {label: 'Герб', data: 'arms', render: (value: number) => {String(value)}}, ] return ( - {fields.map(({label, data}) => ( + {fields.map(({label, data, render}) => ( {label} - + + {render ? render(record?.[data]) : } ))}