fix: association value submitted on demand
This commit is contained in:
parent
52ed4f488a
commit
cf71111b0a
@ -59,7 +59,7 @@ export const FormBlockProvider = (props) => {
|
||||
!designable && __tableName && !inheritCollections.includes(props.collection) && __tableName !== props.collection;
|
||||
return (
|
||||
!flag && (
|
||||
<BlockProvider {...props}>
|
||||
<BlockProvider {...props} block={'form'}>
|
||||
<InternalFormBlockProvider {...props} />
|
||||
</BlockProvider>
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ import { message, Modal } from 'antd';
|
||||
import parse from 'json-templates';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import get from 'lodash/get';
|
||||
import omit from 'lodash/omit';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useReactToPrint } from 'react-to-print';
|
||||
@ -69,6 +70,16 @@ const filterValue = (value) => {
|
||||
};
|
||||
|
||||
function getFormValues(filterByTk, field, form, fieldNames, getField, resource) {
|
||||
if (filterByTk) {
|
||||
const actionFields = field?.data?.activeFields as Set<string>;
|
||||
if (actionFields) {
|
||||
const keys = Object.keys(form.values).filter((key) => {
|
||||
const f = getField(key);
|
||||
return !actionFields.has(key) && ['hasOne', 'hasMany', 'belongsTo', 'belongsToMany'].includes(f?.type);
|
||||
});
|
||||
return omit({ ...form.values }, keys);
|
||||
}
|
||||
}
|
||||
return form.values;
|
||||
let values = {};
|
||||
for (const key in form.values) {
|
||||
@ -640,4 +651,4 @@ export const useDetailsPaginationProps = () => {
|
||||
textAlign: 'center',
|
||||
},
|
||||
};
|
||||
};
|
||||
};
|
||||
|
@ -4,10 +4,10 @@ import { Field } from '@formily/core';
|
||||
import { ISchema, useField, useFieldSchema } from '@formily/react';
|
||||
import { uid } from '@formily/shared';
|
||||
import _ from 'lodash';
|
||||
import React from 'react';
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ACLCollectionFieldProvider } from '../../../acl/ACLProvider';
|
||||
import { useFilterByTk, useFormBlockContext } from '../../../block-provider';
|
||||
import { BlockRequestContext, useFilterByTk, useFormBlockContext } from '../../../block-provider';
|
||||
import { useCollection, useCollectionManager } from '../../../collection-manager';
|
||||
import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings';
|
||||
import { useCompile, useDesignable, useFieldComponentOptions } from '../../hooks';
|
||||
@ -26,6 +26,15 @@ const divWrap = (schema: ISchema) => {
|
||||
|
||||
export const FormItem: any = (props) => {
|
||||
const field = useField();
|
||||
const ctx = useContext(BlockRequestContext);
|
||||
const schema = useFieldSchema();
|
||||
useEffect(() => {
|
||||
if (ctx?.block === 'form') {
|
||||
ctx.field.data = ctx.field.data || {};
|
||||
ctx.field.data.activeFields = ctx.field.data.activeFields || new Set();
|
||||
ctx.field.data.activeFields.add(schema.name);
|
||||
}
|
||||
}, []);
|
||||
return (
|
||||
<ACLCollectionFieldProvider>
|
||||
<BlockItem className={'nb-form-item'}>
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { ISchema, Schema, useFieldSchema, useForm } from '@formily/react';
|
||||
import { uid } from '@formily/shared';
|
||||
import React, { useState } from 'react';
|
||||
import React, { useContext, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { SchemaInitializerItemOptions } from '../';
|
||||
import { BlockRequestContext, SchemaInitializerItemOptions } from '../';
|
||||
import { useCollection, useCollectionManager } from '../collection-manager';
|
||||
import { useActionContext, useDesignable } from '../schema-component';
|
||||
import { useSchemaTemplateManager } from '../schema-templates';
|
||||
@ -427,10 +427,18 @@ export const useCurrentSchema = (action: string, key: string, find = findSchema,
|
||||
}
|
||||
const { remove } = useDesignable();
|
||||
const schema = find(fieldSchema, key, action);
|
||||
const ctx = useContext(BlockRequestContext);
|
||||
const exists = !!schema;
|
||||
|
||||
return {
|
||||
schema,
|
||||
exists: !!schema,
|
||||
remove() {
|
||||
if (ctx.field) {
|
||||
ctx.field.data = ctx.field.data || {};
|
||||
ctx.field.data.activeFields = ctx.field.data.activeFields || new Set();
|
||||
ctx.field.data.activeFields.delete(schema.name);
|
||||
}
|
||||
schema && rm(schema, remove);
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user