Only accept future dates (v2023)

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
sclg
User
Posts: 153
Location: UK

Only accept future dates (v2023)

Post 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


mobhar
User
Posts: 11745

Post by mobhar »

You may search in this forum by using minDate keyword.


sclg
User
Posts: 153
Location: UK

Post 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


iggabz
User
Posts: 87

Post 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


sclg
User
Posts: 153
Location: UK

Post 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!


mobhar
User
Posts: 11745

Post 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.


sclg
User
Posts: 153
Location: UK

Post 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?


mobhar
User
Posts: 11745

Post by mobhar »

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

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


sclg
User
Posts: 153
Location: UK

Post 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.


mobhar
User
Posts: 11745

Post 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".


Post Reply