Make date/time selector only allow present and future time?

Make date/time selector only allow present and future time?

by Justin Peterson -
Number of replies: 2

Hello

I am developing my first Moodle plugin, and was looking for documentation on the moodle form date_time_selector object with little luck.

I would like a user to only be able to select a date and time that is in the present or future (it is used to book a video conference, and wouldn't be too useful if a user could book a conference in the past :P)

I figured I would be able to do it with the addRule function, but I'm not finding any documented way to do so.

Any help would be appreciated. Thanks in advance smile 

 

 

 

Average of ratings: -
In reply to Justin Peterson

תשובה ל: Make date/time selector only allow present and future time?

by Raphael Goldman -

Hi

You can do it in the validation function.

if the field name is starttime for example

$errors = parent::validation($data, $files);

if ($data['starttime'] < time()']) {
$errors['starttime'] = get_string('starttime_error', 'file');
}

 

Average of ratings: Useful (2)
In reply to Raphael Goldman

Re: תשובה ל: Make date/time selector only allow present and future time?

by Justin Peterson -

Worked well. Thank you!