Skip to content

Commit

Permalink
fix: defaultValue类型为number时的bug (#3288)
Browse files Browse the repository at this point in the history
  • Loading branch information
DesignHhuang committed Nov 16, 2023
1 parent 100f3cf commit 3b2760c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/Form/src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ export function processDateValue(attr: Recordable, component: string) {
}
}

export const defaultValueComponents = [
'Input',
'InputPassword',
'InputNumber',
'InputSearch',
'InputTextArea',
];

export function handleInputNumberValue(component?: ComponentType, val?: any) {
if (!component) return val;
if (['Input', 'InputPassword', 'InputSearch', 'InputTextArea'].includes(component)) {
if (defaultValueComponents.includes(component)) {
return val && isNumber(val) ? `${val}` : val;
}
return val;
Expand All @@ -74,8 +82,6 @@ export function handleInputNumberValue(component?: ComponentType, val?: any) {
*/
export const dateItemType = genType();

export const defaultValueComponents = ['Input', 'InputPassword', 'InputSearch', 'InputTextArea'];

// TODO 自定义组件封装会出现验证问题,因此这里目前改成手动触发验证
export const NO_AUTO_LINK_COMPONENTS: ComponentType[] = [
'Upload',
Expand Down

1 comment on commit 3b2760c

@zwtvip
Copy link
Contributor

@zwtvip zwtvip commented on 3b2760c Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还是没有彻底解决

{
    field: 'type',
    label: '菜单类型',
    component: 'RadioButtonGroup',
    defaultValue: 0,
    componentProps: {
      options: [
        { label: '目录', value: 0 },
        { label: '菜单', value: 1 },
        { label: '按钮', value: 2 },
      ],
    },
    colProps: { lg: 24, md: 24 },
  },

setFieldsValue({
      type: 2,
 });

这样去设置还是不生效,即使把RadioButtonGroup加入defaultValueComponents,也不行,把isEmpty(currentFieldsValue[item.field]) 去掉就可以了 updateSchema 在 setFieldsValue 后面执行会把_setDefaultValue这个方法走一遍,这个判断本身就有问题:

_.isEmpty(null);
// => true
 
_.isEmpty(true);
// => true
 
_.isEmpty(1);
// => true
 
_.isEmpty([1, 2, 3]);
// => false
 
_.isEmpty({ 'a': 1 });
// => false

Please sign in to comment.