Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-8289

Calculated question 1.8 new forms bug: an item is deleted (or added) when typing ENTER in one of the <input> fields in datasetitems_form.php

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • 1.8
    • Questions
    • None

      When you type the ENTER key on a <input> field of the item values in datasetitems_form.php, the default submit button used is the first one on the form.
      When there is at least one item, this the DELETE ITEM submit button .
      So if you type the ENTER key, an item will be DELETED.(and the values update if the item remains!!!)

      If there is no items, the first submit button is ADD ITEM
      So if you type the ENTER key, an item will be ADDED (and the dataset definitions will be updated!!)

      A first easy modification is to put an additional submit button that will be ignored by the actual code so the default process will be applied.
      Actually the default is to update the items values and some of the fields of the definitions.

      something like
      if ($i == $this->noofitems)

      {//last item $mform->addElement('submit', 'modifyitemvalues', get_string('MODIFY ITEM AND DEFINITION VALUES ', 'qtype_datasetdependent')); $mform->addElement('submit', 'deletebutton', get_string('deletelastitem', 'qtype_datasetdependent')); }

      and MODIFY DATASET ITEM VALUES values before the ADD ITEM submit button when there no one item value displayed.
      In this case when you type ENTER this
      so the lines after if ($i == $this->noofitems) {//last item
      can be like

      if ($i == $this->noofitems)

      {//last item $mform->addElement('submit', 'modifyitemvalues', get_string('UPDATE DATASET ITEM AND DEFINITION VALUES ', 'qtype_datasetdependent')); $mform->addElement('submit', 'deletebutton', get_string('deletelastitem', 'qtype_datasetdependent')); }

      }
      $mform->setType("itemid", PARAM_INT);
      $mform->setType("definition", PARAM_NOTAGS);

      if ( $this->noofitems == 0 )

      { $mform->addElement('submit', 'modifydatadefsvalues', get_string('UPDATE DATASET DEFINITION VALUES', 'qtype_datasetdependent')); $mform->addElement('submit', 'addbutton', get_string('additem', 'qtype_datasetdependent')); $mform->closeHeaderBefore('modifydatadefsvalues'); }

      else

      { $mform->addElement('submit', 'addbutton', get_string('additem', 'qtype_datasetdependent')); $mform->closeHeaderBefore('addbutton'); }

      The solution has been applied in the following url user: moodle pw:moodle
      choosing one calculated question (i.e id = 21)

            timhunt Tim Hunt
            ppichet Pierre Pichet (Inactive)
            Pierre Pichet Pierre Pichet (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.