Adding optional date selector to mod_form

Adding optional date selector to mod_form

by SVI eSolutions -
Number of replies: 3

Hi, I wished to add an optional "date_time_selector" to my mod form, which was rather easy, just add optional => true...

But I don't want it checked by default... I don't want to disable it either. 

I would like it to appear like the second one here... But all I get is like the first one or completely disabled...


Is there an attribute I can add? 

Does anyone have any suggestions, I thought this would be simple...

Average of ratings: -
In reply to SVI eSolutions

Re: Adding optional date selector to mod_form

by Darko Miletić -

Check this thread

https://moodle.org/mod/forum/discuss.php?d=326417

Essentially solution for your issue is to NOT specify default value for date time selector.

In reply to Darko Miletić

Re: Adding optional date selector to mod_form

by SVI eSolutions -

I do not specify a default value.

All I add is the following :

$mform->addElement('date_time_selector', 'datebegin', get_string('date', 'via'), array('optional' => true));

In reply to SVI eSolutions

Re: Adding optional date selector to mod_form

by Darko Miletić -

OK, now I understand what you want. And that is not how datetime works. You can either get it enabled with check or disabled without check.