fix: exception when deleting object with formula fields in sub-form (#4897)

This commit is contained in:
Katherine 2024-07-18 17:53:03 +08:00 committed by GitHub
parent ed937d5f18
commit 22b85677c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,7 +20,6 @@ import {
useFormBlockContext, useFormBlockContext,
ActionContext, ActionContext,
} from '@nocobase/client'; } from '@nocobase/client';
import { debounce } from 'lodash';
import { Evaluator, evaluators } from '@nocobase/evaluators/client'; import { Evaluator, evaluators } from '@nocobase/evaluators/client';
import { Registry, toFixedByStep } from '@nocobase/utils/client'; import { Registry, toFixedByStep } from '@nocobase/utils/client';
import React, { useEffect, useState, useContext } from 'react'; import React, { useEffect, useState, useContext } from 'react';
@ -74,13 +73,11 @@ export function Result(props) {
const fieldPath = path?.replace(`.${fieldSchema.name}`, ''); const fieldPath = path?.replace(`.${fieldSchema.name}`, '');
const fieldName = fieldPath.split('.')[0]; const fieldName = fieldPath.split('.')[0];
const index = parseInt(fieldPath.split('.')?.[1]); const index = parseInt(fieldPath.split('.')?.[1]);
const ctx = useContext(ActionContext);
useEffect(() => { useEffect(() => {
setEditingValue(value); setEditingValue(value);
}, [value]); }, [value]);
useFormEffects(() => { useFormEffects(() => {
const delayedOnChange = debounce(props.onChange, 300);
onFormValuesChange((form) => { onFormValuesChange((form) => {
if ( if (
(fieldSchema.name as string).indexOf('.') >= 0 || (fieldSchema.name as string).indexOf('.') >= 0 ||
@ -102,8 +99,9 @@ export function Result(props) {
setEditingValue(v); setEditingValue(v);
} }
setEditingValue(v); setEditingValue(v);
delayedOnChange(v); if (v !== field.value) {
ctx?.setFormValueChanged?.(false); field.value = v;
}
}); });
}); });
const Component = TypedComponents[dataType] ?? InputString; const Component = TypedComponents[dataType] ?? InputString;