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

implement availableTimes property for DateTimePicker #988

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zhisme
Copy link

@zhisme zhisme commented Jan 24, 2020

Hello!

I needed one feature for my work project, so I implemented this in your library.
Business task was set like so:

Person need to select time only in working hours e.g. (8 AM - 8 PM)

As I couldn't achieve it by timeComponent, because it renders empty li tags that can be clicked, I modified getDates function in order to achieve this goal.
Hope you will find my PR useful

@zhisme zhisme requested a review from jquense January 24, 2020 14:12
@zhisme
Copy link
Author

zhisme commented Nov 4, 2020

@jquense any feedback? 🙂

@jquense
Copy link
Owner

jquense commented Nov 5, 2020

hey, sorry, its too easy to lose track of pending GH PRs. Thanks for this, I think it's neat and useful, but i'm not sure it's a good fit here. It may be better to provide a more general API for achieving this, such as filterTimes: (date) => true

@OpakAlex
Copy link

OpakAlex commented Nov 5, 2020

nice feature, thanks!

@zhisme
Copy link
Author

zhisme commented Nov 6, 2020

@jquense hey. can you describe a little more, how can I adjust the code?
filterTimes: (arrayOfDates) => true at least needs to get an array to achieve this on my opinion

@jquense
Copy link
Owner

jquense commented Nov 6, 2020

I was thinking something like array.filter so you only provide the rejector function and the component here will only use dates you return true for

@siropkin
Copy link

Here is my workaround - to empty timeList options if time out of range and hide empty options by css style.

css

  .rw-list-option:empty {
    display: none;
  }

component:

    <DateTimePicker
      {...tail}
      timeComponent={({ value, text }) => {
        return value.getHours() >= 7 && value.getHours() <= 18 ? text : '';
      }}
    />

@jquense jquense force-pushed the master branch 2 times, most recently from c76e0f3 to 459ab78 Compare July 7, 2021 20:02
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

Successfully merging this pull request may close these issues.

4 participants