jQuery-Autocomplete icon indicating copy to clipboard operation
jQuery-Autocomplete copied to clipboard

Visibility problems with preserveInput=true

Open MorbZ opened this issue 10 years ago • 8 comments

If preserveInput is enabled there is a problem that occurs (happens in all mayor browsers).

Reproduce: Bug A)

  1. Select a suggestion item with the mouse -> The textfield loses focus and the suggestion list disappears
  2. Click the textfield again -> Bug: The suggestions box shows up and after a few milliseconds it disappears again

Bug B)

  1. Select a suggestion item with the arrow keys and press return -> Bug: The suggestions list disappears and after a few milliseconds it is shown again.

Bug A and B probably result from the same code. It must have something to do the killerFn().

A partial fix would be:

--- jquery.autocomplete.js  2015-03-14 21:22:50.000000000 +0100
+++ jquery.autocomplete2.js 2015-03-15 00:31:32.000000000 +0100
@@ -147,7 +147,7 @@
            that.element.setAttribute('autocomplete', 'off');

            that.killerFn = function (e) {
-                if ($(e.target).closest('.' + that.options.containerClass).length === 0) {
+                if ($(e.target).closest('.' + that.options.containerClass).length === 0 && !that.options.preserveInput) {
                 that.killSuggestions();
                 that.disableKillerFn();
             }

But that only fixes Bug A and is causes new problems (the textfield doesn't lose focus when outside is clicked).

MorbZ avatar Mar 14 '15 23:03 MorbZ

Probably I'll do a pull request later, but as a quick fix you can try it now:

Fix bug A
@@ line 325 
        enableKillerFn: function () {
            var that = this;
-            $(document).on('click.autocomplete', that.killerFn);
+           $(document).one('click.autocomplete', that.killerFn);
        },


Fix bug B
@@ line 433
            case keys.DOWN:
+          case keys.RETURN:
                    return;


                case keys.RETURN:

zycbob avatar Mar 20 '15 06:03 zycbob

Hi,

For fix bug B, ill recommend that adding the line "that.killerFn(e);" in the "case keys.Return:"

case keys.RETURN: if (that.selectedIndex === -1) { that.hide(); return; } that.select(that.selectedIndex); that.killerFn(e); <--- line added

The reason I added this line and has fixed bug B, its because this function is called after clicking a suggestion, but its not called while key pressing.

RobertoGalvan avatar Dec 28 '15 23:12 RobertoGalvan

Hi,

I'm facing bug B as well.

Could you please take a look on it?

DAfanasyev avatar Dec 20 '17 21:12 DAfanasyev

No news about this issue ? I'm also having problem B

Mushr0000m avatar Jan 04 '18 15:01 Mushr0000m

Hello,

I haven't seen any update or release regarding this bug.

Have you tried using the "workaround" I suggested?

RobertoGalvan avatar Jan 04 '18 16:01 RobertoGalvan

The killerFn() doesn't exists anymore. In my case I think the problem appears because I change the input value after the user select something, so somehow Autocomplete think it's a different value. It works with the TAB because there is a return.

Mushr0000m avatar Jan 04 '18 16:01 Mushr0000m

Then you almost got your problem solved. What I did on the time I worked on it, was to see how it worked in both scenarios. Saying that, see what part of the TAB scenarios is doing the expected behavior.

Hope it works.

RobertoGalvan avatar Jan 04 '18 16:01 RobertoGalvan

Any fix to this issue yet? Seeing this still.

jersingh avatar Mar 05 '19 00:03 jersingh