fix(plugin-workflow): fix expression field in sub-form (#2324)
This commit is contained in:
parent
0de4458936
commit
80779c3a98
@ -1,5 +1,5 @@
|
|||||||
import { onFieldInputValueChange, onFormInitialValuesChange } from '@formily/core';
|
import { onFieldInputValueChange, onFormInitialValuesChange } from '@formily/core';
|
||||||
import { connect, mapReadPretty, observer, useForm, useFormEffects } from '@formily/react';
|
import { connect, mapReadPretty, observer, useField, useForm, useFormEffects } from '@formily/react';
|
||||||
import { Tag } from 'antd';
|
import { Tag } from 'antd';
|
||||||
import React, { useMemo, useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -12,16 +12,20 @@ import { getCollectionFieldOptions } from '../variable';
|
|||||||
const InternalExpression = observer(
|
const InternalExpression = observer(
|
||||||
(props: any) => {
|
(props: any) => {
|
||||||
const { onChange } = props;
|
const { onChange } = props;
|
||||||
const { values } = useForm();
|
const field = useField<any>();
|
||||||
const [collection, setCollection] = useState(values?.sourceCollection);
|
// TODO(refactor): better to provide another context like useFieldset()
|
||||||
|
const form = useForm();
|
||||||
|
const basePath = field.path.segments.slice(0, -1);
|
||||||
|
const collectionPath = [...basePath, 'sourceCollection'].join('.');
|
||||||
|
const [collection, setCollection] = useState(form.getValuesIn(collectionPath));
|
||||||
const compile = useCompile();
|
const compile = useCompile();
|
||||||
const { getCollectionFields } = useCollectionManager();
|
const { getCollectionFields } = useCollectionManager();
|
||||||
|
|
||||||
useFormEffects(() => {
|
useFormEffects(() => {
|
||||||
onFormInitialValuesChange((form) => {
|
onFormInitialValuesChange((form) => {
|
||||||
setCollection(form.values.sourceCollection);
|
setCollection(form.getValuesIn(collectionPath));
|
||||||
});
|
});
|
||||||
onFieldInputValueChange('sourceCollection', (f) => {
|
onFieldInputValueChange(collectionPath, (f) => {
|
||||||
setCollection(f.value);
|
setCollection(f.value);
|
||||||
onChange(null);
|
onChange(null);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user