fix: view collection association field foreignkey should be select (#3671)

This commit is contained in:
katherinehhh 2024-03-12 09:30:38 +08:00 committed by GitHub
parent cdf9f4818f
commit 4a346a4119
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -221,11 +221,11 @@ export const ForeignKey = observer(
const { getCollection } = useCollectionManager_deprecated(); const { getCollection } = useCollectionManager_deprecated();
const record = useRecord(); const record = useRecord();
const field: any = useField(); const field: any = useField();
const { collectionName, target, type, through, name } = record; const { collectionName, target, type, through, name, template } = record;
const value = record[field.props.name]; const value = record[field.props.name];
const compile = useCompile(); const compile = useCompile();
const form = useForm(); const form = useForm();
const [initialValue, setInitialValue] = useState(value || field.initialValue); const [initialValue, setInitialValue] = useState(value || (template === 'view' ? null : field.initialValue));
useEffect(() => { useEffect(() => {
const effectField = ['belongsTo'].includes(type) const effectField = ['belongsTo'].includes(type)
? collectionName ? collectionName
@ -251,9 +251,10 @@ export const ForeignKey = observer(
} }
} }
}, [type]); }, [type]);
const Compoent = template === 'view' ? Select : AutoComplete;
return ( return (
<div> <div>
<AutoComplete <Compoent
disabled={disabled} disabled={disabled}
value={initialValue} value={initialValue}
options={options} options={options}