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

Antd 4.0.0 <DatePicker /> uses setFieldsValue update error in <Form /> #20206

Closed
1 task done
SolidZORO opened this issue Dec 12, 2019 · 7 comments
Closed
1 task done
Assignees
Labels
4.x In Ant Design 4.0 🐛 Bug Ant Design Team had proved that this is a bug.

Comments

@SolidZORO
Copy link
Contributor

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

export const DatePickerUpdateTest = () => {
  const initTime = '2077-07-07 07:07:07';

  const [form] = Form.useForm();

  useEffect(() => {
    form.setFieldsValue({ time: moment(initTime) });
  }, [form]);

  return (
    <div style={{ padding: 20 }}>
      <Form form={form} name="infoForm" layout="vertical">
        <Form.Item name="time" rules={[]} label="TIME">
          <DatePicker showTime />
        </Form.Item>
      </Form>

      <Button type="primary" onClick={() => form.setFields([{ name: 'time', value: moment() }])}>
        Success Update
      </Button>

      <Button
        danger
        style={{ marginLeft: 10 }}
        // TODO console get some error
        // Uncaught TypeError: val.isValid is not a function
        // The above error occurred in the <PickerWrapper> component:
        onClick={() => form.setFieldsValue({ time: moment() })}
      >
        Fail Update
      </Button>
    </div>
  );
};

more code: https://codesandbox.io/s/antd-400-datepicker-uses-setfieldsvalue-update-error-in-form-efrp9

What is expected?

setFieldsValue can correctly verify moment() or Date.

What is actually happening?

setFieldsValue check for moment() or Date error. but setFields succeeds. why?

Environment Info
antd 4.0.0-alpha.14
React 16.12.0
System macOS 10.15.1 (19B88)
Browser Chrome 78.0.3904.108
@wpbjiuy
Copy link

wpbjiuy commented Jan 19, 2021

##我也遇到了同样的问题,请问解决了吗?
refForm.current?.setFieldsValue({ ...slcData.current, birthday: '2020-01-22' })

Error:

moment.js:105 Uncaught TypeError: date.clone is not a function at Object.format (moment.js:105)

@yoyo837
Copy link
Contributor

yoyo837 commented Jan 19, 2021

birthday 给 moment实例

@ergomesh
Copy link

https://codepen.io/ergomesh/pen/ZEywWyW?editors=0110

Same here can not get any initialValues to load correctly and it breaks the whole page I have tried moment date and string representations. This particular example is in a form.list but it also happens outside of it.

@radrianhp
Copy link

anyone get solve about this issue ? I get same issue error
Version 4.19.5

@ppulwey
Copy link

ppulwey commented Jul 6, 2022

If you cast your Date object into moment object first, this error disappears.

@Hassanjankhan
Copy link

@ppulwey please provide and example

@QiuYeDx
Copy link

QiuYeDx commented May 17, 2024

今天我也出现了这个报错,然后发现,在set之前,用dayjs库给入参(元数据)的日期时间字符串包裹一下生成dayjs的日期对象就没有那个报错了,just like this:

value: dayjs(eventInfo.date)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x In Ant Design 4.0 🐛 Bug Ant Design Team had proved that this is a bug.
Projects
None yet
Development

No branches or pull requests

10 participants