Skip to content
Browse files

MDL-28972 formslib: orignalvalue is considered and checkboxes are upd…

…ated depending on orignalvalue of controller
  • Loading branch information...
1 parent 2961a37 commit 62b3a99a0d7514ea18ad557ac1290f26394bd615 @rajeshtaneja rajeshtaneja committed Mar 9, 2012
Showing with 28 additions and 14 deletions.
  1. +28 −14 lib/formslib.php
View
42 lib/formslib.php
@@ -1042,40 +1042,54 @@ function repeat_elements($elementobjs, $repeats, $options, $repeathiddenname,
function add_checkbox_controller($groupid, $text = null, $attributes = null, $originalValue = 0) {
global $CFG, $PAGE;
+ // Name of the controller button
+ $checkboxcontrollername = 'nosubmit_checkbox_controller' . $groupid;
+ $checkboxcontrollerparam = 'checkbox_controller'. $groupid;
+ $checkboxgroupclass = 'checkboxgroup'.$groupid;
+
// Set the default text if none was specified
if (empty($text)) {
$text = get_string('selectallornone', 'form');
}
$mform = $this->_form;
- $select_value = optional_param('checkbox_controller'. $groupid, null, PARAM_INT);
+ $select_value = optional_param($checkboxcontrollerparam, null, PARAM_INT);
+ $contollerbutton = optional_param($checkboxcontrollername, null, PARAM_ALPHAEXT);
+ $new_select_value = $select_value;
if (is_null($select_value)) {
- $new_select_value = 0;
- } else {
+ $new_select_value = $originalValue;
+ } else if (!is_null($contollerbutton)) {
$new_select_value = (int) !$select_value;
}
+ // set checkbox state depending on orignal/submitted value by controoler button
+ if (!is_null($contollerbutton) || is_null($select_value)) {
+ foreach ($mform->_elements as $element) {
+ if (($element instanceof MoodleQuickForm_advcheckbox) &&
+ $element->getAttribute('class') == $checkboxgroupclass) {
+ $mform->setConstants(array($element->getName() => $new_select_value));
+ }
+ }
+ }
- $mform->addElement('hidden', "checkbox_controller".$groupid, null, array('id' => "id_checkbox_controller".$groupid));
- $mform->setType("checkbox_controller$groupid", PARAM_INT);
- $mform->setConstants(array("checkbox_controller$groupid" => $new_select_value));
-
- $checkbox_controller_name = 'nosubmit_checkbox_controller' . $groupid;
- $mform->registerNoSubmitButton($checkbox_controller_name);
+ $mform->addElement('hidden', $checkboxcontrollerparam, $new_select_value, array('id' => "id_".$checkboxcontrollerparam));
+ $mform->setType($checkboxcontrollerparam, PARAM_INT);
+ $mform->setConstants(array($checkboxcontrollerparam => $new_select_value));
$PAGE->requires->yui_module('moodle-form-checkboxcontroller', 'M.form.checkboxcontroller',
array(
array('groupid' => $groupid,
- 'checkboxclass' => 'checkboxgroup'.$groupid,
- 'checkboxcontroller' => "checkbox_controller".$groupid,
- 'controllerbutton' => $checkbox_controller_name)
+ 'checkboxclass' => $checkboxgroupclass,
+ 'checkboxcontroller' => $checkboxcontrollerparam,
+ 'controllerbutton' => $checkboxcontrollername)
)
);
require_once("$CFG->libdir/form/submit.php");
- $submitlink = new MoodleQuickForm_submit($checkbox_controller_name, $attributes);
+ $submitlink = new MoodleQuickForm_submit($checkboxcontrollername, $attributes);
$mform->addElement($submitlink);
- $mform->setDefault($checkbox_controller_name, $text);
+ $mform->registerNoSubmitButton($checkboxcontrollername);
+ $mform->setDefault($checkboxcontrollername, $text);
}
/**

0 comments on commit 62b3a99

Please sign in to comment.
Something went wrong with that request. Please try again.