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

Option valuehtmlcallback is not evaluated when autocomplete is inside a group

XMLWordPrintable

    • MOODLE_310_STABLE, MOODLE_39_STABLE
    • MOODLE_310_STABLE, MOODLE_39_STABLE
    • MDL-71039-master
    • Hide

      Stealing some testing instructions from MDL-66297:

      1. Login as a teacher in a course
      2. Create a forum
      3. Post in the forum
      4. In the forum settings choose "Forum summary report"
      5. Push "Export" button next to any name
        1. Confirm that the user is pre-selected
        2. Confirm that the user's full name is shown in the autocomplete element (not just id)
      6. Apply the patch:

        git am ~/path/to/0001-71039.patch
        

      7. Open the same "Export" page
        1. Confirm that the user is pre-selected
        2. Confirm that the user's full name is shown in the autocomplete element (not just id)
      Show
      Stealing some testing instructions from MDL-66297 : Login as a teacher in a course Create a forum Post in the forum In the forum settings choose "Forum summary report" Push "Export" button next to any name Confirm that the user is pre-selected Confirm that the user's full name is shown in the autocomplete element (not just id) Apply the patch: git am ~/path/to/0001-71039.patch Open the same "Export" page Confirm that the user is pre-selected Confirm that the user's full name is shown in the autocomplete element (not just id)

      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]));
      

        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

            marina Marina Glancy
            marina Marina Glancy
            David Carrillo David Carrillo
            Andrew Lyons Andrew Lyons
            Janelle Barcega Janelle Barcega
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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