fix(association-field): allow multiple (#1938)
This commit is contained in:
parent
849956b8ea
commit
efbd7c7020
@ -312,7 +312,7 @@ export default {
|
||||
"Display association fields": "显示关联表的字段",
|
||||
"Display field title": "显示字段标题",
|
||||
"Field component": "字段组件",
|
||||
"Allow multiple": "允许多选",
|
||||
"Allow multiple": "允许添加/关联多条",
|
||||
"Quick upload": "快速上传",
|
||||
"Select file": "选择文件",
|
||||
"Subtable": "子表格",
|
||||
|
@ -8,6 +8,7 @@ export const AssociationFieldProvider = observer((props) => {
|
||||
const field = useField<Field>();
|
||||
const { getCollectionJoinField, getCollection } = useCollectionManager();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const allowMultiple = fieldSchema['x-component-props']?.multiple !== false;
|
||||
|
||||
const collectionField = useMemo(
|
||||
() => getCollectionJoinField(fieldSchema['x-collection-field']),
|
||||
@ -23,7 +24,7 @@ export const AssociationFieldProvider = observer((props) => {
|
||||
);
|
||||
|
||||
return collectionField ? (
|
||||
<AssociationFieldContext.Provider value={{ options: collectionField, field, currentMode }}>
|
||||
<AssociationFieldContext.Provider value={{ options: collectionField, field, allowMultiple, currentMode }}>
|
||||
{props.children}
|
||||
</AssociationFieldContext.Provider>
|
||||
) : null;
|
||||
|
@ -24,7 +24,7 @@ const ToOneNester = (props) => {
|
||||
|
||||
const ToManyNester = observer((props) => {
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { field } = useAssociationFieldContext<ArrayField>();
|
||||
const { field, allowMultiple } = useAssociationFieldContext<ArrayField>();
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Card bordered={true} style={{ position: 'relative' }}>
|
||||
@ -48,7 +48,7 @@ const ToManyNester = observer((props) => {
|
||||
</>
|
||||
);
|
||||
})}
|
||||
{field.editable && (
|
||||
{field.editable && allowMultiple && (
|
||||
<Button
|
||||
type={'dashed'}
|
||||
block
|
||||
|
@ -4,7 +4,8 @@ import { createContext } from 'react';
|
||||
export interface AssociationFieldContextProps {
|
||||
options?: any;
|
||||
field?: GeneralField;
|
||||
currentMode?:string;
|
||||
currentMode?: string;
|
||||
allowMultiple?: boolean;
|
||||
}
|
||||
|
||||
export const AssociationFieldContext = createContext<AssociationFieldContextProps>({});
|
||||
|
@ -30,7 +30,12 @@ export const useInsertSchema = (component) => {
|
||||
};
|
||||
|
||||
export function useAssociationFieldContext<F extends GeneralField>() {
|
||||
return useContext(AssociationFieldContext) as { options: any; field: F; currentMode: string };
|
||||
return useContext(AssociationFieldContext) as {
|
||||
options: any;
|
||||
field: F;
|
||||
currentMode: string;
|
||||
allowMultiple?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export default function useServiceOptions(props) {
|
||||
|
Loading…
Reference in New Issue
Block a user