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

Autocomplete selects first or last option by default if a list is provided with no selected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.0
    • JavaScript
    • None
    • MOODLE_400_STABLE

      I'm using Moodle's Autocomplete element using a select with a defined list of options, I don't use an AJAX call to load them. There are cases where there will be no selected option, but the Autocomplete element automatically displays either the first or the last option as selected.

      If I define all the options with no selected attribute (e.g. <option value="x">) then Autocomplete detects the first option as selected. If I define all options with selected="false" then Autocomplete detects the last option as selected. I'm not sure if this is caused by jQuery or by the HTML itself, this line says true for the first or last option.

      IMO if there is no option specified as selected the Autocomplete should display the no selection string, as it does when you remove the selected option.

      This is my Mustache code:

      <select id="assignedto-select" class="form-autocomplete-original-select">
          #assignableusers
               <option value="id"#selected}}selected{{/selected>fullname</option>
          /assignableusers
      </select>

       
      And this is my JS code:

      Autocomplete.enhance('#assignedto-select', false, '', placeholderString, false, true, undefined, true);

            Unassigned Unassigned
            dpalou Dani Palou
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

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