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

Course autocomplete fields with multiple values cannot be edited when using ajax

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 3.1
    • Component/s: Forms Library
    • Labels:
    • Testing Instructions:
      Hide
      1. Download and access the file test_form_autocomplete.php.
        • If you don't have courses with ID 2 and 3, edit the file to change the IDs in course_multiple_presets_form. Also make sure you have more courses than those two.
      2. Confirm that course_multiple_preset_form with courses pre-selected.
      3. Confirm that courses are still selected after validation error. (Click 'Error' button)
      4. Confirm that the right IDs are passed upon save.
      Show
      Download and access the file test_form_autocomplete.php . If you don't have courses with ID 2 and 3, edit the file to change the IDs in course_multiple_presets_form . Also make sure you have more courses than those two. Confirm that course_multiple_preset_form with courses pre-selected. Confirm that courses are still selected after validation error. (Click 'Error' button) Confirm that the right IDs are passed upon save.
    • Affected Branches:
      MOODLE_31_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-53889-master

      Description

      If you create a form with an autocomplete field that allows multiple selection, and call set_data with a list of values, "No selection" is displayed instead of the list of options.
      This only happens when the fields are loaded in via AJAX.

      Example code (assumes you have created two courses):

      $mform->addElement('course', 'test', 'I am a test', array(
         'multiple' => true,
      ));
      $mform->set_data(array('test' => [2,3]));
      

      Looking through form-autocomplete.js I got to:

      originalSelect.children('option').each(function(index, ele) {
                  if ($(ele).prop('selected')) {
                      items.push( { label: $(ele).html(), value: $(ele).attr('value') } );
                  }
              });
      

      "$(ele).prop('selected')" is returning false for all elements of a multi-select, when every element is actually a valid item for the template.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                23/May/16