Ant-design-mobile: DatePicker结合rc-form的setFieldsValue赋值时出现的问题

Created on 1 Jun 2017  ·  6Comments  ·  Source: ant-design/ant-design-mobile

Version

1.1.3

Environment

antd-mobile 1.1.3,react 15.5.4 ,rc-form 1.3.1

Reproduction link

https://codepen.io/chengky/pen/rmrBBV

Steps to reproduce

1.DatePicker组件不设置format,点击“设置日期”按扭(使用了rc-form的setFieldsValue赋值),此时报错:
date-picker/utils.tsx 24行,Uncaught TypeError: t.format is not a function
2.按照提示给DatePicker组件设置format,此时再点击“设置日期”按扭赋值正确,但点击日历组件时报错:
rmc-date-picker/lib/DatePicker.tsx 171行,Uncaught TypeError: a.year is not a function

What is expected?

rc-form的setFieldsValue赋值后,日历使用正常

What is actually happening?

Uncaught TypeError: a.year is not a function
    at Object.getDateData (DatePicker.js:171)
    at Object.getValueCols (DatePicker.js:349)
    at Object.render (DatePicker.js:362)
    at p._renderValidatedComponentWithoutOwnerOrContext (react-dom.min.js:13)
    at p._renderValidatedComponent (react-dom.min.js:13)
    at performInitialMount (react-dom.min.js:13)
    at p.mountComponent (react-dom.min.js:13)
    at Object.mountComponent (react-dom.min.js:14)
    at h.mountChildren (react-dom.min.js:14)
    at h._createInitialChildren (react-dom.min.js:13)

Most helpful comment

DatePicker上的 format只是显示用?
那使用时,一般获取数据源初始值为字符串,则在使用rc-form的initialValue时需要转换为moment对象
然后保存时又需要转换为字符串

当前应用场景就是大json构造多个日期的复杂表单,每次都要单独把日期进行转换,感觉不合理。
建议value可以为string,并在DatePicker组件上增加转换方法可以string转为moment对像

All 6 comments

It will be better to write your issue/comment in English, so more people can understand you.
And this means that more people can help you or benefit from your issue/comment.
See: https://github.com/ant-design/ant-design/issues/4897

DatePickervalue 是个 moment 对象,不能传 string.

@yesmeck 谢谢。原来moment().format()后变成了字符串

DatePicker上的 format只是显示用?
那使用时,一般获取数据源初始值为字符串,则在使用rc-form的initialValue时需要转换为moment对象
然后保存时又需要转换为字符串

当前应用场景就是大json构造多个日期的复杂表单,每次都要单独把日期进行转换,感觉不合理。
建议value可以为string,并在DatePicker组件上增加转换方法可以string转为moment对像

真是个好组件啊,真好用😅😅

antd mobile 2.0 会去掉 momemt.js

Was this page helpful?
0 / 5 - 0 ratings