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

'on blur' on the autocomplete element breaks form functionality

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Test #1

      1. Log in as admin
      2. Go to Site Home
      3. Click on the cog icon and chose "more"
      4. Go to Question bank > questions
      5. Create a new question of any type. For example a True/False question
      6. After you created the question, click on the tag icon next to the question in the question bank
      7. Enter "t1" in the tag element but do not click Enter
      8. Without clicking anywhere else on the page press "Save changes"
      9. Click on the tag icon for the question again and verify that the question is tagged with "t1"
      10. Enter "t2" in the tag element but do not click Enter
      11. Do this step very quick (in less than half a second)
        1. press tab
        2. press enter
      12. Click on the tag icon for the question again and verify that the question is tagged with "t1" and "t2"

      Test #2

      1. Download the test patch: 0001-MDL-65102-calendar-TEST-PATCH.patch to your Moodle instance's root folder.
      2. On your terminal, go to your moodle root folder and apply the test patch: "git am 0001-MDL-65102-calendar-TEST-PATCH.patch"
      3. Purge the caches.
      4. Go to your dashboard and click on month name in the calendar block
      5. Open JS console
      6. Press "New event"
      7. Fill the name of the event
      8. Enter something in the tag element but do not click Enter
      9. Without clicking anywhere else on the page press "Submit"
      10. Verify that you don't see any error in the console coming from createItem
      Show
      Test #1 Log in as admin Go to Site Home Click on the cog icon and chose "more" Go to Question bank > questions Create a new question of any type. For example a True/False question After you created the question, click on the tag icon next to the question in the question bank Enter "t1" in the tag element but do not click Enter Without clicking anywhere else on the page press "Save changes" Click on the tag icon for the question again and verify that the question is tagged with "t1" Enter "t2" in the tag element but do not click Enter Do this step very quick (in less than half a second) press tab press enter Click on the tag icon for the question again and verify that the question is tagged with "t1" and "t2" Test #2 Download the test patch: 0001-MDL-65102-calendar-TEST-PATCH.patch to your Moodle instance's root folder. On your terminal, go to your moodle root folder and apply the test patch: " git am 0001- MDL-65102 -calendar-TEST-PATCH.patch " Purge the caches. Go to your dashboard and click on month name in the calendar block Open JS console Press "New event" Fill the name of the event Enter something in the tag element but do not click Enter Without clicking anywhere else on the page press "Submit" Verify that you don't see any error in the console coming from createItem
    • Affected Branches:
      MOODLE_36_STABLE
    • Fixed Branches:
      MOODLE_35_STABLE, MOODLE_36_STABLE
    • Pull from Repository:
    • Pull 3.5 Branch:
    • Pull 3.6 Branch:
    • Pull Master Branch:
      MDL-65102-master
    • Sprint:
      Workplace for Moodle 3.7

      Description

      I am working on a modal form that contains an autocomplete element to add tags and I just found out that if I type a new tag and I press Save on the form (without pressing enter or clicking anywhere else in the form) I get this exception message:

       

       

      jquery-3.2.1.js:3860 jQuery.Deferred exception: Cannot read property 'split' of undefined TypeError: Cannot read property 'split' of undefined at createItem

       

      This happens because on blur tries to work with an element that no longer exists. One proposal to solve this problem that Marina gave me could be adding

      && $('#' + state.inputId).length

      on this if condition:

      --- a/lib/amd/src/form-autocomplete.js
      +++ b/lib/amd/src/form-autocomplete.js
      @@ -709,7 +709,7 @@ function($, log, str, templates, notification, LoadingIcon) {
                       var focusElement = $(document.activeElement);                 // Only close the menu if the input hasn't regained focus.
      -                if (focusElement.attr('id') != inputElement.attr('id')) {
      +                if (focusElement.attr('id') != inputElement.attr('id') && $('#' + state.inputId).length) {
                           if (options.tags) {
                               pendingPromise.then(function() {
                                   return createItem(options, state, originalSelect);

       

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                13/May/19

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 6 hours, 30 minutes
                6h 30m