Select the first day available in a datetime field

Select the first day available in a datetime field

MathewPocketMathewPocket Posts: 4Questions: 1Answers: 0

Hi Everyone,

First, thanks to Allan for this wonderful tool !

I try something very simple I think. I have a datatable of products with a start date and an end date.

When I change the start date, I change dynamically the min value of end date, and when I change the end date, the max value of the start field is changed too...

This is the use case where I got a problem :

I start with my both fields empty
I fill the start value with a date in future (example : 25/11/2020)
My code change the min value of my end field so every day between today and the 25/11/2020 is disable and that's great but when the calendar appear, the first page of the calendar I see is "march" and the day highlighted id the 17 (ie the day of now) so I have to go manually to the November month, to see the first day I can choose.

=> I want, in this case, when I click to modify the end date, that the calendar open dynamically with the first available day.
Is a easy way to do that?

I tried to do that with the field().def() when I change the min value of the field but it seems don't work.

Thanks for your help

Answers

  • colincolin Posts: 8,033Questions: 0Answers: 1,349

    You can set the default value for an date with def, there's an example of it on that page. It fills in the input box with the value, but would that work - running example here.

    Colin

  • MathewPocketMathewPocket Posts: 4Questions: 1Answers: 0

    Hi,

    Thanks for your answer but it's not exactly what I'm looking for.

    the def() function set a date in the field, so when you open the date picker , the date with is highlighted in blue, is the date you set with the def function.

    for my case, when I set a start date in the future, I automatically set the min of the end date with the start date value. But when I click on my end date to set an end date value, when the date picker is open, the hi lighted value is the current date, and I have to go manually to my first available date ... I'll try to put an live exemple ...

  • MathewPocketMathewPocket Posts: 4Questions: 1Answers: 0

    Ok there is my example (sorry for the design):
    live.datatables.net/wafoyoqo/1/edit

    On the line line, the "date debut" is set with the 20/06/20 (date in the future)
    When you edit the "date fin" with double click on it, the date picker open.
    The date of today is highlighted, (20/03/20)
    Every days between the 20/03/20 and 20/11/20 are disabled (it's ok because I set the min end date = start date)

    => What I want is when the date picker open, I want to be directly on the 20/06/20

  • allanallan Posts: 51,422Questions: 1Answers: 7,754 Site admin

    Just looking over the code - I don't quite get it I'm afraid. You've got click event listeners inside the table, but not for the form itself. Let's take the New form as an example as that's the most trivial case.

    I would expect there to be a dependent() handler attached to your start date. Inside that handler you would then set the minDate for the end date and also the value (note not the default - the default is used only when the form is initially shown).

    Does that make sense now?

    Regards,
    Allan

  • MathewPocketMathewPocket Posts: 4Questions: 1Answers: 0

    Hi

    Thanks for your answer :) the dependant API method is a good idea, I'll try but I think that if I set the value of the end date field, I will show it in my table, right?
    Because, In my application, the end date is not mandatory...

  • allanallan Posts: 51,422Questions: 1Answers: 7,754 Site admin

    but I think that if I set the value of the end date field, I will show it in my table, right?

    Correct. I see a little bit of a problem here - the date picker in Editor will jump the calender display to the date in the input field. If there is no date in the input field, it will show the calender for today.

    That's a problem for our use case since you want it to show something in the future, even when it is an empty value.

    Perhaps the solution would be to check if the minDate is > current date. If so, then jump to the minDate since you can't select below that anyway... Would that work for you?

    Allan

Sign In or Register to comment.