diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index a531061cd5b..aebac23db2f 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -173,16 +173,21 @@ abstract class moodleform_mod extends moodleform { } } - if ($mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly') and empty($COURSE->groupmodeforce)) { - $mform->disabledIf('groupingid', 'groupmode', 'eq', NOGROUPS); + // Don't disable/remove groupingid if it is currently set to something, + // otherwise you cannot turn it off at same time as turning off other + // option (MDL-30764) + if (empty($this->_cm) || !$this->_cm->groupingid) { + if ($mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly') and empty($COURSE->groupmodeforce)) { + $mform->disabledIf('groupingid', 'groupmode', 'eq', NOGROUPS); - } else if (!$mform->elementExists('groupmode') and $mform->elementExists('groupmembersonly')) { - $mform->disabledIf('groupingid', 'groupmembersonly', 'notchecked'); + } else if (!$mform->elementExists('groupmode') and $mform->elementExists('groupmembersonly')) { + $mform->disabledIf('groupingid', 'groupmembersonly', 'notchecked'); - } else if (!$mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly')) { - // groupings have no use without groupmode or groupmembersonly - if ($mform->elementExists('groupingid')) { - $mform->removeElement('groupingid'); + } else if (!$mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly')) { + // groupings have no use without groupmode or groupmembersonly + if ($mform->elementExists('groupingid')) { + $mform->removeElement('groupingid'); + } } }