MDL-65506 forms: get the correct value for advcheckbox fields in js

This commit is contained in:
Shamim Rezaie 2019-05-09 12:22:30 +08:00
parent f1a8db6911
commit 706c5b3acd
2 changed files with 8 additions and 10 deletions

View File

@ -55,8 +55,8 @@ class data_controller extends \core_customfield\data_controller {
$field = $this->get_field();
$config = $field->get('configdata');
$elementname = $this->get_form_element_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.
// If checkbox is required (i.e. "agree to terms") then use 'checkbox' form element.
// The advcheckbox element cannot be used for required fields because advcheckbox elements always provide a value.
$isrequired = $field->get_configdata_property('required');
$mform->addElement($isrequired ? 'checkbox' : 'advcheckbox', $elementname, $this->get_field()->get_formatted_name());
$mform->setDefault($elementname, $config['checkbydefault']);

View File

@ -302,15 +302,13 @@ class HTML_QuickForm_RuleRegistry
" }\n";
}
} elseif ($element->getType() == 'advcheckbox') {
$value = " value{$jsIndex} = frm.elements['$elementName'][1].checked ?" .
" frm.elements['$elementName'][1].value : frm.elements['$elementName'][0].value;\n";
$tmp_reset .= $reset ? " field[1].checked = field[1].defaultChecked;\n" : '';
} elseif ($element->getType() == 'checkbox') {
if (is_a($element, 'html_quickform_advcheckbox')) {
$value = " value{$jsIndex} = frm.elements['$elementName'][1].checked? frm.elements['$elementName'][1].value: frm.elements['$elementName'][0].value;\n";
$tmp_reset .= $reset ? " field[1].checked = field[1].defaultChecked;\n" : '';
} else {
$value = " value{$jsIndex} = frm.elements['$elementName'].checked? '1': '';\n";
$tmp_reset .= $reset ? " field.checked = field.defaultChecked;\n" : '';
}
$value = " value{$jsIndex} = frm.elements['$elementName'].checked? '1': '';\n";
$tmp_reset .= $reset ? " field.checked = field.defaultChecked;\n" : '';
} elseif ($element->getType() == 'radio') {
$value = " value{$jsIndex} = '';\n" .
// Fix for bug #5644