Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-1659

Prolem with 'mouseactive' in wicket-autocomplete.js when AutoCompleteBehaviour is added (twice) during Ajax roundtrip

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.4-M1
    • 1.3.4, 1.4-M3
    • wicket-extensions
    • None

    Description

      There is a subtle problem, with the way how the autocomplete menu is created lazily in wicket-autocomplete.js when
      the AbstractAutoCompleteBehaviour is used dynamically in Ajax roundtrips e.g. for adding addition auto complete
      fields dynamically.

      The auto complete menu is added as an addition <div> to the document and stays there even after an Ajax roundtrip, so
      the <div> is reused, as well as mouse event listeners on the menu:

      function getAutocompleteMenu() {
      var choiceDiv=document.getElementById(getMenuId());
      if (choiceDiv==null) {
      var container = document.createElement("div");
      ....
      container.onmouseout=function()

      { mouseactive=0; }

      ;
      container.onmousemove=function()

      { mouseactive=1; }

      };

      However, since Wicket.AutoComplete get initialized a second time for during the Ajax update, a new mouseactive variable is created, which
      is used in the closures for tweaking the even handling (onChange(), onBlur()), which never gets updated by these reused container (and hence
      is always 0).

      One simple solution to this problem is to cleanup the autocomplete menu in the initialize() if present:

      function initialize(){

      // Remove the autocompletion menu if still present from
      // a previous call. This is required to properly register
      // the mouse event handler again (using the new stateful 'mouseactive'
      // variable which just gets created)
      var choiceDiv=document.getElementById(this.getMenuId());
      if (choiceDiv != null)

      { choiceDiv.parentNode.parentNode.removeChild(choiceDiv.parentNode); }

      .....
      }

      Attachments

        Activity

          People

            jcompagner Johan Compagner
            roland.huss Roland Huss
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: