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

This commit is contained in:
Dan Poltawski 2016-12-19 12:21:06 +00:00
commit 64e032b6da
3 changed files with 11 additions and 0 deletions

View File

@ -181,6 +181,7 @@ abstract class feedback_item_base {
* If it is important which mode the form is in, use $form->get_mode()
*
* Each item type must add a single form element with the name $item->typ.'_'.$item->id
* This element must always be present in form data even if nothing is selected (i.e. use advcheckbox and not checkbox).
* To add an element use either:
* $form->add_form_element() - adds a single element to the form
* $form->add_form_group_element() - adds a group element to the form

View File

@ -350,11 +350,16 @@ class feedback_item_multichoice extends feedback_item_base {
}
} else {
// Radio.
if (!array_key_exists(0, $options)) {
// Always add '0' as hidden element, otherwise form submit data may not have this element.
$objs[] = ['hidden', $inputname.'[0]'];
}
foreach ($options as $idx => $label) {
$objs[] = ['radio', $inputname.'[0]', '', $label, $idx];
}
$element = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class);
$form->set_element_default($inputname.'[0]', $tmpvalue);
$form->set_element_type($inputname.'[0]', PARAM_INT);
}
}

View File

@ -305,12 +305,17 @@ class feedback_item_multichoicerated extends feedback_item_base {
['select', $inputname, $name, array('' => '') + $options, array('class' => $class)]);
} else {
$objs = array();
if (!array_key_exists(0, $options)) {
// Always add '0' as hidden element, otherwise form submit data may not have this element.
$objs[] = ['hidden', $inputname];
}
foreach ($options as $idx => $label) {
$objs[] = ['radio', $inputname, '', $label, $idx];
}
$separator = $info->horizontal ? ' ' : '<br>';
$class .= ' multichoicerated-' . ($info->horizontal ? 'horizontal' : 'vertical');
$el = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class);
$form->set_element_type($inputname, PARAM_INT);
// Set previously input values.
$form->set_element_default($inputname, $form->get_item_value($item));