General developer forum

 
 
Picture of Justin Peterson
Make date/time selector only allow present and future time?
 

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: -
Picture of Raphael Goldman
תשובה ל: Make date/time selector only allow present and future time?
 

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)
Picture of Justin Peterson
Re: תשובה ל: Make date/time selector only allow present and future time?
 

Worked well. Thank you!

 
Average of ratings: -