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

[Bug] :disabled-time disables time starting from next hour #384

Closed
plakhin opened this issue Nov 29, 2019 · 18 comments
Closed

[Bug] :disabled-time disables time starting from next hour #384

plakhin opened this issue Nov 29, 2019 · 18 comments

Comments

@plakhin
Copy link

plakhin commented Nov 29, 2019

Vue2-datepicker version: 3.1.1
Vue version: 2.6.10
Browser: Chrome 78

Steps to reproduce
:disabled-time="(date) => date < new Date()"

Expected behavior
Lets suppose current time is 15:33:03
User should be able to select 15:33:04 and later

Actual behavior
User can able to select 16:00:00 and later.

@mengxiong10
Copy link
Owner

You can set default-value= new Date().

@plakhin
Copy link
Author

plakhin commented Dec 1, 2019

Thanks for response, but how it will help?
I have a field with value already inserted from database. I need an option to forbid dates and time in past. disabled-time seems what I need, but it disables time during current hour.
Adding default-value seems to give no affect in my case.

@mengxiong10
Copy link
Owner

If your value is null, You should set the default-value. let the default-value is valid.
If your value from database is invalid. Maybe you should give a message and not bind the value.
Can you write a CodeSandbox link.

@plakhin
Copy link
Author

plakhin commented Dec 2, 2019

https://jsfiddle.net/mfw2L3co/

Please try to select time 1 minute from now(). It is not possible.
I.e. if now() is 12:33:00 the nearest time possible to select is 13:00:00

@mengxiong10
Copy link
Owner

mengxiong10 commented Dec 2, 2019

You should set the value of default-value is not disabled.
When you select a date but the time is disabled, the component should update the date by defaultValue.
But the default-value is invalid when type === datetime now.
I'll fix it.

mengxiong10 added a commit that referenced this issue Dec 2, 2019
When switching date causes time is disabled, the time of `defaultValue` should be used by default.
@plakhin
Copy link
Author

plakhin commented Dec 3, 2019

I've updated to last version, but still no result, or I just can't understand how to use default-value.

Can you edit my jsfiddle please and paste the link here?
I just need working example with past dates/time unselectable.

@mengxiong10
Copy link
Owner

v3.2.1.
https://jsfiddle.net/aqw3ypLo/9/

@mengxiong10
Copy link
Owner

mengxiong10 commented Dec 3, 2019

disabledTime = date < '2019-12-03 14:30:30';
  1. the initial value is 2019-11-29 12:00:00.
  2. when you select 2019-12-04, the value will be 2019-12-04 12:00:00 (retain the time).
  3. when you select 2019-12-03. the value will be 2019-12-03 12:00:00, but the value is disabled. So You can set a default-value="2019-12-03 14:30:31", then the value will be 2019-12-03 14:30:31.

@mengxiong10
Copy link
Owner

Set the default value to fall back when the value is disabled

@mengxiong10
Copy link
Owner

Supposedisabled-time = date < '2019-12-03 16:30:30'.
Because the default time is '00:00:00', the time 16:00:00 is disabled cause the hour 4 cann't be selected.
When you set the default value is '16:30:31', then the hour 4 can be selected, because '16:30:31' isn't disabled.

@plakhin
Copy link
Author

plakhin commented Dec 3, 2019

Finally, works and now it's clear about default-value. Thanks!

@plakhin plakhin closed this as completed Dec 3, 2019
@plakhin
Copy link
Author

plakhin commented Mar 11, 2020

@mengxiong10 please check https://jsfiddle.net/tvaz230r/3/

I changed format from "YYYY-MM-DD HH:mm:ss" to format="YYYY-MM-DD HH:mm" and now it's broken again. Can you help please?

@plakhin plakhin reopened this Mar 11, 2020
@mengxiong10
Copy link
Owner

:default-value="now.getTime() + 1000 * 60"

@plakhin
Copy link
Author

plakhin commented Mar 18, 2020

Thanks! This works in example. But I have more complicated actual use case.
Can you please check https://jsfiddle.net/plakhin/tjx4cL2m/8/

I'll really appreciate. Can't understand what I'm doing wrong.

@plakhin
Copy link
Author

plakhin commented Mar 19, 2020

@mengxiong10 can you help please?

@mengxiong10
Copy link
Owner

@plakhin When select the date, you should check the time.

@mengxiong10
Copy link
Owner

 <time-panel
       :value="slotProps.value < new Date() ? new Date(Date.now() + 60 * 1000) : slotProps.value"
  ></time-panel>

@plakhin
Copy link
Author

plakhin commented Mar 19, 2020

Works perfect! Thanks!

@plakhin plakhin closed this as completed Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants