Skip to content

Commit

Permalink
MDL-38094 question forms: remove spare repeat element blanks.
Browse files Browse the repository at this point in the history
Once the question has been created, only so as many blanks as are
required by the current question. Adding a new answer / choice / unit /
etc. is a rare operation, so it is OK if it takes another mouse click.
It is better to keep the form shorter in the common case.
  • Loading branch information
timhunt committed Feb 28, 2013
1 parent cce0d9a commit c3c65f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
9 changes: 2 additions & 7 deletions question/type/edit_question_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,9 @@ protected function add_per_answer_fields(&$mform, $label, $gradeoptions,
$repeatedoptions, $answersoption);

if (isset($this->question->options)) {
$countanswers = count($this->question->options->$answersoption);
$repeatsatstart = count($this->question->options->$answersoption);
} else {
$countanswers = 0;
}
if ($this->question->formoptions->repeatelements) {
$repeatsatstart = max($minoptions, $countanswers + $addoptions);
} else {
$repeatsatstart = $countanswers;
$repeatsatstart = $minoptions;
}

$this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions,
Expand Down
15 changes: 7 additions & 8 deletions question/type/numerical/edit_numerical_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qtype_numerical_edit_form extends question_edit_form {
/** @var int we always show at least this many sets of unit fields. */
const UNITS_MIN_REPEATS = 1;
const UNITS_TO_ADD = 2;

protected $ap = null;

protected function definition_inner($mform) {
Expand Down Expand Up @@ -146,18 +150,13 @@ protected function add_unit_fields($mform) {
$mform->disabledIf('addunits', 'unitrole', 'eq', qtype_numerical::UNITNONE);

if (isset($this->question->options->units)) {
$countunits = count($this->question->options->units);
} else {
$countunits = 0;
}
if ($this->question->formoptions->repeatelements) {
$repeatsatstart = $countunits + 1;
$repeatsatstart = max(count($this->question->options->units), self::UNITS_MIN_REPEATS);
} else {
$repeatsatstart = $countunits;
$repeatsatstart = self::UNITS_MIN_REPEATS;
}

$this->repeat_elements($unitfields, $repeatsatstart, $repeatedoptions, 'nounits',
'addunits', 2, get_string('addmoreunitblanks', 'qtype_numerical', '{no}'), true);
'addunits', self::UNITS_TO_ADD, get_string('addmoreunitblanks', 'qtype_numerical', '{no}'), true);

// The following strange-looking if statement is to do with when the
// form is used to move questions between categories. See MDL-15159.
Expand Down

0 comments on commit c3c65f4

Please sign in to comment.