Form date selector doesn't disable

Form date selector doesn't disable

Jack Finan發表於
Number of replies: 3
I'm trying to make a form with a date selector with the 'enabled' checkbox. I added it like this:

$mform->addElement('date_selector', 'startdate', get_string('from'), ['optional' => true]);

The ['optional' => true] parameter added the checkbox, but it doesn't do anything. Am I supposed to implement that myself? I looked through the code for other date selectors but couldn't find any logic related to this, besides the 'optional' attribute.


評比平均分數: -
In reply to Jack Finan

Re: Form date selector doesn't disable

AL Rachels發表於
Core developers的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片
Have you tried adding as an array with a step? Here is an example that I know works.
$mform->addElement('date_time_selector', 'timeopen', get_string('hotquestionopentime', 'hotquestion'), array('optional' => true, 'step' => 1));
In reply to Jack Finan

Re: Form date selector doesn't disable

Jack Finan發表於
I noticed the calendar button also doesn't work, so it seems like javascript is broken on this page. I've never set up a new page before so it's probably not set up correctly.
This is my page setup:

require_once('../../config.php');
// Ensure the user is allowed to view this page. require_login(null, false); $context = context_system::instance(); require_capability('moodle/site:viewreports', $context);
// Initialise $PAGE. global $PAGE, $SITE; $pageurl = new moodle_url('/local/enrolreport/view.php'); $PAGE->set_url($pageurl); $PAGE->set_context($context); $PAGE->set_title(get_string('pluginname', 'local_enrolreport')); $PAGE->set_heading($SITE->fullname); $PAGE->set_pagelayout('standard');

Is there anything here that stands out? Or any other reason why javascript may not be working?