Page 1 of 1

Only accept future dates (v2023)

Posted: Thu Apr 25, 2024 2:41 am
by sclg

How can I make the date picker (or a date field in general) only accept dates from today onwards - Refusing all dates before today?
Thanks


Re: Only accept future dates

Posted: Thu Apr 25, 2024 9:12 am
by mobhar

You may search in this forum by using minDate keyword.


Re: Only accept future dates

Posted: Thu Apr 25, 2024 5:55 pm
by sclg

The problem seems to be getting todays date in a format TimePicker likes in the Advanced-Fields options. Reading all those posts, people have used
"minDate":today (today undefined)
"minDate":Moment() (Moment is not defined)
"minDate:Date() (Using string for date error)

I've tried all these both with {restrictions{"minDate":Moment()}} and with {"minDate":Moment()} and I get the same errors with both
(The former seems to be what the TP documentation says but none of the posts here mention it.)

I'm sure this must be something stupidly simple, but what??
Thanks


Re: Only accept future dates

Posted: Thu Apr 25, 2024 6:31 pm
by iggabz

hello. hope this helps you with your concern.

    $today = date("Y-m-d H:i:s");
    $date1 = $this->date_filed->CurrentValue;
    if ($date1 <= $today) {
        $customError = "your custom error message";
            return FALSE;
    }

i have place this on the table specific->Add/copy page -> form_customvalidate


Re: Only accept future dates

Posted: Thu Apr 25, 2024 6:34 pm
by sclg

Thanks. I know I could do that but it defeats the object of using the TimePicker. If the TimePicker can be setup correctly, then it prevents anyone even selecting an earlier date!


Re: Only accept future dates

Posted: Thu Apr 25, 2024 8:23 pm
by mobhar

Even though you can prevent to select date that previous than today via DateTimePicker, you still need validation from server side, since end-users are still be able to change the date by changing the value from the Textbox control.


Re: Only accept future dates

Posted: Fri Apr 26, 2024 12:38 am
by sclg

Thanks, but I was intending to make the date text box read-only so they had to use the DatePicker.
However I'm still stuck on getting today's date. Following ideas in other posts I've tried...

{restrictions:{"minDate":"today"}}
Unable to parse provided input: today, format: dd/MM/y

{restrictions:{"minDate":Moment()}}
Uncaught ReferenceError: Moment is not defined

{restrictions:{"minDate":moment()}}
Uncaught ReferenceError: moment is not defined

{restrictions:{"minDate":[]}}
Uncaught Error: TD: Could not correctly parse "" to a date for restrictions.minDate.

Any thoughts?


Re: Only accept future dates

Posted: Fri Apr 26, 2024 9:35 am
by mobhar

Change this code:
{restrictions:{"minDate":"today"}}

to:
{restrictions: {"minDate": "<?php echo CurrentDate(); ?>"} }


Re: Only accept future dates

Posted: Fri Apr 26, 2024 7:19 pm
by sclg

Thanks but that didn't work and gave the warning....
TD: Using a string for date options is not recommended unless you specify an ISO string or use the customDateFormat plugin.


Re: Only accept future dates (v2023)

Posted: Fri Apr 26, 2024 11:09 pm
by mobhar

I tried with v2024, and it works properly. It should work also for v2023.

In addition, make sure you have already adjusted the locale setting (Tools -> Locale Settings) for date directive as "yyyy-MM-dd".