Only accept future dates (v2023)
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
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
You may search in this forum by using minDate
keyword.
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
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
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!
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.
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?
Change this code:
{restrictions:{"minDate":"today"}}
to:
{restrictions: {"minDate": "<?php echo CurrentDate(); ?>"} }
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.
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"
.