JQuery autocomplete in dialog errors

Everything,

I am using jQuery Autocomplete Plugin 1.0.2 in the jQuery interface dialog box. Unfortunately, there are 2 scripts in IE and FireFox that cause script errors . I will provide FireFox Firebug errors as they are more visual.

First of all, this is a jQuery script autocomplete that allows you to select multiple names:

var queues = <% Html.RenderAction("AvailableQueues"); %>;
$($.jqId("requestQueuesText"), $theForm).autocomplete(queues, {
    minChars: 1,
    formatItem: function(row) {
        return row.Description;                
    },
    multiple: true,
    multipleSeparator: ";"
 });

Now here are two scenarios that cause errors:


1) Enter a space "" before anything else, and I immediately get

ERROR: currentValue undefined ; onChange () jquery.a ... mplete.js (line 239); [Break on this error] if (currentValue.length> = options.minChars) {

2) Close the dialog when the autocomplete drop-down list is open, but without selecting an item

* , . . , , , . , .

: : [... " : 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLTextAreaElement.setSelectionRange]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame:: http://localhost:2659/Scripts/jquery.autocomplete.js:: anonymous:: 752" data: no]


, , formatItem -.

, BGIFRAME, , , .

!

+3
1

, keydown :

var queues = <% Html.RenderAction("AvailableQueues"); %>;
    $($.jqId("requestQueuesText"), $theForm).autocomplete(queues, {
        minChars: 1,
        formatItem: function(row) {
            return row.Description;                
        },
        multiple: true,
        multipleSeparator: ";",
        selectFirst: false
    }).keydown(function(event) {
        if (this.value != "" && this.value.charAt(this.value.length-1) != ";")
            return true;

        var keycode = $.browser.msie ? event.keyCode : event.which;
        return !/\s/.test(String.fromCharCode(keycode));
    });

(multipleSeparator).

- # 2. , hover click $('a.close-trigger'), focus() , , , ... , :

$(".requestLink").click(function(event) {
        event.preventDefault();
        var $this = $(this);
        $this.addClass("loading");
        $.get(this.href, function(data) {
            $this.removeClass("loading");
            var $req = $("<div></div>").dialog({
                autoOpen: true,
                height: 650,
                width: 750,
                modal: true,
                title: "Request",
                overlay: { "background-color": "#d2d2d2", "opacity": "0.40"}
            }).html(data);
        });
    });
+1

Source: https://habr.com/ru/post/1708350/


All Articles