Permalink
Browse files

MDL-38094 question forms: remove spare repeat element blanks.

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...
1 parent cce0d9a commit c3c65f417ae1a119c5d7bcf3a65f5c97981ac890 @timhunt timhunt committed Feb 27, 2013
Showing with 9 additions and 15 deletions.
  1. +2 −7 question/type/edit_question_form.php
  2. +7 −8 question/type/numerical/edit_numerical_form.php
View
9 question/type/edit_question_form.php
@@ -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,
View
15 question/type/numerical/edit_numerical_form.php
@@ -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) {
@@ -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.

0 comments on commit c3c65f4

Please sign in to comment.