Merge branch 'MDL-65523-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Sara Arjona 2019-05-09 08:46:30 +02:00
commit 465ed6f107

View File

@ -55,10 +55,13 @@ class data_controller extends \core_customfield\data_controller {
$field = $this->get_field();
$config = $field->get('configdata');
$elementname = $this->get_form_element_name();
$mform->addElement('advcheckbox', $elementname, $this->get_field()->get_formatted_name());
// TODO MDL-65506 element 'advcheckbox' does not support 'required' rule. If checkbox is required (i.e. "agree to terms")
// then use 'checkbox' form element.
$isrequired = $field->get_configdata_property('required');
$mform->addElement($isrequired ? 'checkbox' : 'advcheckbox', $elementname, $this->get_field()->get_formatted_name());
$mform->setDefault($elementname, $config['checkbydefault']);
$mform->setType($elementname, PARAM_BOOL);
if ($field->get_configdata_property('required')) {
if ($isrequired) {
$mform->addRule($elementname, null, 'required', null, 'client');
}
}