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

Option valuehtmlcallback is not evaluated when autocomplete is inside a group

    XMLWordPrintable

    Details

      Description

      Autocomplete element has option valuehtmlcallback that allows to evaluate the display values of pre-selected elements. It works fine normally.

      However if the autocomplete element is part of a group, it is ignored.

      The autocomplete element is used with the valuehtmlcallback three times in Moodle LMS and actually all of them are not even needed because these forms can never have preselected values.

      Here is the example how to reproduce it. Apply the following patch to the Moodle LMS, go to any forum and select "Export" from the settings menu. You should see the name of the user preselected in "User" autocomplete element but instead you see id.

      diff --git a/mod/forum/classes/form/export_form.php b/mod/forum/classes/form/export_form.php
      index fb571f94263..a59a7bb9d6c 100644
      --- a/mod/forum/classes/form/export_form.php
      +++ b/mod/forum/classes/form/export_form.php
      @@ -66,7 +66,9 @@ class export_form extends \moodleform {
                           return $OUTPUT->render_from_template('mod_forum/form-user-selector-suggestion', $useroptiondata);
                       }
               ];
      -        $mform->addElement('autocomplete', 'useridsselected', get_string('users'), [], $options);
      +        $group = [];
      +        $group[] = $mform->createElement('autocomplete', 'useridsselected', get_string('users'), [], $options);
      +        $mform->addGroup($group, 'useridsselectedgroup', get_string('users'), '', false);
       
               // Get the discussions on this forum.
               $vaultfactory = \mod_forum\local\container::get_vault_factory();
      diff --git a/mod/forum/export.php b/mod/forum/export.php
      index 9aee3f18809..ba9d5170cc6 100644
      --- a/mod/forum/export.php
      +++ b/mod/forum/export.php
      @@ -78,6 +78,7 @@ $context = $forum->get_context();
       $form = new mod_forum\form\export_form($url->out(false), [
           'forum' => $forum
       ]);
      +$form->set_data(['useridsselected' => [$USER->id]]);
       
       if ($form->is_cancelled()) {
           redirect(new moodle_url('/mod/forum/view.php', ['id' => $cm->id]));
      

        Attachments

        1. 0001-71039.patch
          1 kB
        2. image-2021-03-24-11-14-10-347.png
          image-2021-03-24-11-14-10-347.png
          108 kB
        3. withgroup.png
          withgroup.png
          30 kB
        4. withoutgroup.png
          withoutgroup.png
          31 kB

          Issue Links

            Activity

              People

              Assignee:
              marina Marina Glancy
              Reporter:
              marina Marina Glancy
              Peer reviewer:
              David Matamoros David Matamoros
              Integrator:
              Andrew Lyons Andrew Lyons
              Tester:
              Janelle Barcega Janelle Barcega
              Participants:
              Component watchers:
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                25/Mar/21

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour, 35 minutes
                  1h 35m