How do you trigger autocomplete “select” event manually in jQueryUI?

后端 未结 10 1397
别跟我提以往
别跟我提以往 2020-12-01 09:28

I\'m using jQueryUI autocomplete, and I have a function mapped to the select event, e.g.:

$(\"#someId\").autocomplete({
    source: someData,
    select: fun         


        
10条回答
  •  盖世英雄少女心
    2020-12-01 09:37

    I found very simple way to make it work. Answers above did not work for me.

    My input definition:

    
    

    The autocomplete definition:

    $('#search-user-id').autocomplete({
        minChars: 3,
        paramName: 'searchTerm',
        deferRequestBy: 200, // This is to avoid js error on fast typing
        serviceUrl: '${pageContext.request.contextPath}/settings/reset/psw/query',
        type: 'POST',
        onSelect : function(suggestion) {
            showUserData(suggestion.dto);
        }, 
        onSearchError: function (query, jqXHR, textStatus, errorThrown) {
            $('.cev-error-fields.reset-password').find('.error_msg').text(errorThrown).show().fadeOut(7000);
        }
    }); 
    

    Trigger it: I am triggering from an ajax defined in other page, I do not put the ajax here for simplicity. Inside the ajax response I just trigger it this way:

            $('#search-user-id').val(username);
            $('#search-user-id').focus();
    

    It worked.

提交回复
热议问题