Element: [Bug Report] While using 'value-format' in date-range-picker and giving value ['', ''], it resets to 1970-01-01

Created on 7 Jun 2018  ·  11Comments  ·  Source: ElemeFE/element

Element UI version

2.4.0

OS/Browsers version

Win10 Chrome66 x64

Vue version

2.5.17-beta.0

Reproduction Link

https://jsfiddle.net/coolucifer/nw9v5fux/35/

Steps to reproduce

create a el-date-picker and set value-format="yyyy-MM-dd", v-model a value equals ['', ''], click the date-picker
image

What is Expected?

just like other date-picker it shows this month and next month

What is actually happening?

it shows 1970-01 and 1970-02

Most helpful comment

@wacky6 thank you for your reply. Now i watch value binds date-picker with 'value-format' and when i clear date-pickers, i will set the value [] from null(for ['', ''] will reset the calendar to 1970). At the same time i try to get beginDate by value[0], and endDate by value[1], it has errors for there is no value[1], i have to validate it everytime when the value changes, it's a little stupid. Is it possible to make date-picker binded ['', ''] with 'value-format' and without 'value-format' have the same performance?

All 11 comments

empty value must be falsy, such as null, "". Array with empty strings are considered non-empty

@wacky6 when i click the date-range-picker without 'value-format' v-modeled ['', ''] it shows this month and next month, while the date-picker with 'value-format' shows 1970. is that a bug?
image
https://jsfiddle.net/coolucifer/nw9v5fux/40/

我也遇到了这个问题

As said, use null or "" to represent empty value. Using array will not work, and this is intentional, to remain consistent with other component.

"''" is parsed to 1970-1-1 internally.

@wacky6 well...i wonder why it presents two results on two date-range-pickers, is it deliberately to make it 1970 on date-range-picker with 'value-format: 'yyyy-MM-dd'?

What do you mean by two results. The internal parser just happens to parse empty string to that value.

@wacky6 https://jsfiddle.net/coolucifer/nw9v5fux/40/ in this page there are two date-pickers, one has 'value-format' and another doesn't, they are binded the same value '['', '']', but when i click each date-picker it shows different calendars.
this is the one with 'value-format', it shows 1970-01 and 1970-02:
image

and here is the another one without 'value-format', it shows this month and next month:
image

is it caused by 'value-format' or sth else?

Yes. value-format will result in the value being parsed / formatted.

@wacky6 thank you for your reply. Now i watch value binds date-picker with 'value-format' and when i clear date-pickers, i will set the value [] from null(for ['', ''] will reset the calendar to 1970). At the same time i try to get beginDate by value[0], and endDate by value[1], it has errors for there is no value[1], i have to validate it everytime when the value changes, it's a little stupid. Is it possible to make date-picker binded ['', ''] with 'value-format' and without 'value-format' have the same performance?

In that case, you need to wrap your own component.

OK, thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuchonghua picture yuchonghua  ·  3Comments

yubo111 picture yubo111  ·  3Comments

mochenxm picture mochenxm  ·  3Comments

chenzhe-pro picture chenzhe-pro  ·  3Comments

dbskccc picture dbskccc  ·  3Comments