Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BasicForm): setFieldsValue not work in form when use date comp #3819

Merged
merged 2 commits into from
May 9, 2024

Conversation

electroluxcode
Copy link

@electroluxcode electroluxcode commented May 8, 2024

General

✏️ Mark the necessary items without changing the structure of the PR template.

  • Pull request template structure not broken

Type

ℹ️ What types of changes does your code introduce?

👉 Put an x in the boxes that apply

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

fix #3818

@electroluxcode electroluxcode marked this pull request as draft May 8, 2024 09:58
@electroluxcode electroluxcode marked this pull request as ready for review May 8, 2024 10:16
@electroluxcode
Copy link
Author

补一个用于测试的例子

<template>
  <Alert message="bug" />
  <BasicForm @register="registerCustom" class="my-5" />
  <Button @click="set">点我设置值</Button>
</template>

<script setup lang="ts">
  import { Alert, Button } from 'ant-design-vue';
  import { BasicForm, useForm } from '@/components/Form';
  import dayjs from 'dayjs';
  const [registerCustom, { getFieldsValue, setFieldsValue }] = useForm({
    baseColProps: { span: 24 },
    labelWidth: 124,
    schemas: [
      {
        field: '[startTime1, endTime1]',
        label: 'field1',
        component: 'RangePicker',
        componentProps: {
          placeholder: ['开始时间', '结束时间'],
          defaultValue: [dayjs('2024-12-01 11:11:11'), dayjs('2024-12-01 12:12:12')],
        },
      },{
        field: '[startTime2, endTime2]',
        label: '上架时间',
        
        component: 'TimeRangePicker',
        componentProps: {
          format: 'HH:mm:ss',
          placeholder: ['开始时间', '结束时间'],
          defaultValue: [dayjs('11:11:11',"HH:mm:ss"), dayjs('12:12:12',"HH:mm:ss")],
        },
      },
    ],
    showActionButtonGroup: true,
  });
  const set = () => {
    setFieldsValue({
      endTime1: '2028-12-01 12:12:12',
    });
    setFieldsValue({
      startTime2: dayjs('18:18:01',"HH:mm:ss"),
      endTime2: dayjs('19:19:01',"HH:mm:ss"),
    });
    console.log('getFieldsValue:', getFieldsValue());
  };
</script>

@wangjue666 wangjue666 merged commit 7538c57 into vbenjs:main May 9, 2024
2 checks passed
@acegank
Copy link

acegank commented Jul 4, 2024

set的是HH:mm, get后变成了 YYYY-MM-DD HH:mm 了

@acegank
Copy link

acegank commented Jul 4, 2024

在设置了valueFormat 还需要设置value的fomat,源码里只判断了是否有valueFormat,我的理解正常应该要根据valueFormat返回,否则valueFormat没啥意义,就只是个开关

@aTann
Copy link

aTann commented Aug 2, 2024

Adapt common component 处理中,使用了 constructValue = get(value, key); 会导致当 field 使用一些基础类型构造函数原型链上方法名相同的字段时(例如:link),setFieldsValue 会出现返回一个函数的 bug

const formSchemas =  [{
      field: 'link',
      component: 'Input',
      label: '链接',
 }]
 
 setFieldsValue({ link: 'xx' })

image

建议是只对引用类型做 construValue 处理

if (typeof value === 'object' && value !== null) {
   constructValue = get(value, key);
 }

@github-actions github-actions bot locked and limited conversation to collaborators Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RangePicker field为数组时 , setFieldsValue不成功
4 participants