antd踩坑:value.locale is not a function


这个问题来源于日期选择器 RangerPicker 的特殊情况。

                            <Col span={7} key={9}>
                                <FormItem label="投运时间" {...formItemLayout2}>
                                    {getFieldDecorator('tysj', {
                                        initialValue: [undefined, moment().endOf('month')],
                                        rules: [
                                            {
                                                required: false,
                                                message: '投运时间!',
                                            },
                                        ],
                                    })(<RangerPicker style={{ width:'100%'}} format="YYYY-MM-DD" allowClear={true} />)}
                                </FormItem>
                            </Col>

有时我们希望默认值一边有范围,一边没有范围。

比如 几月几号之前。

那么在表单赋值的时候,原先写的是:

initialValue: ['', moment().endOf('month')],

但是这样会导致清除时报错:

value.locale is not a function

而只要改成:

initialValue: [undefined, moment().endOf('month')],

就可以了。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM