Merge pull request #3566 from 2betop/chore-form-item-default-value

chore: 调整表单项默认值的处理, 原来的实现会导致其他场景出问题,换种方式解决 #2674 的问题
This commit is contained in:
RUNZE LU 2022-02-14 14:06:09 +08:00 committed by GitHub
commit 009e865e48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,7 @@ import hoistNonReactStatic from 'hoist-non-react-statics';
import {withRootStore} from '../../WithRootStore';
import {FormBaseControl, FormItemWrap} from './Item';
import {Api} from '../../types';
import {TableStore} from '../../store/table';
export interface ControlOutterProps extends RendererProps {
formStore?: IFormStore;
@ -195,10 +196,13 @@ export function wrapControl<
// 如果没有初始值,通过 onChange 设置过去
if (
this.props.data === this.props.scope &&
onChange &&
typeof propValue === 'undefined' &&
typeof store?.getValueByName(model.name, false) === 'undefined'
typeof store?.getValueByName(model.name, false) === 'undefined' &&
// todo 后续再优化这个判断,
// 目前 input-table 中默认值会给冲掉,所以加上这个判断
// 对应 issue 为 https://github.com/baidu/amis/issues/2674
store?.storeType !== TableStore.name
) {
onChange(model.tmpValue, model.name, false, true);
}