TheGeekZn
TheGeekZn

Reputation: 3914

Changing value and triggering input in IE

I need to forcefully display TypeAhead results once they're loaded.
In the documentation, it states I need to change the value of the input, then change it back to the original (All while triggering the input) to make it work.

I'm using the following code:

    window.setTimeout(function () {
        var val = $(element).val();
        $(element).focus();
        $(element).eq(0).val("").trigger("input");
        $(element).eq(0).val(val).trigger("input");
    }, 500);

This works in Chrome, however, and not IE.

Upvotes: 0

Views: 72

Answers (1)

TheGeekZn
TheGeekZn

Reputation: 3914

Managed to fix this myself with some hacky code:

    var val = $(element).val();

    window.setTimeout(function () {
        $(element).focus();
    }, 50);

    window.setTimeout(function () {
        $(element).eq(0).val("").trigger("keypress");

        window.setTimeout(function () {
            $(element).eq(0).val(val).trigger("keypress");
        }, 80);

    }, 75);

Looks like I need more time between the events... If anyone can see a better way of doing this, I'm open to any ideas.

Edit: For those interested, this does NOT work in Chrome.
Edit 2: This is useless if you're looking for any type of speed or functionality. It breaks away from the clean running of TypeAhead...

Upvotes: 1

Related Questions