xcash / bootstrap-autocomplete

Bootstrap Autocomplete
MIT License
168 stars 72 forks source link

Idea needed #124

Open 4braincells opened 3 years ago

4braincells commented 3 years ago

I am currently filling postal code and town name with 2 autoselects, one of them as follows:

$('.townNameAutoComplete').autoComplete({
        formatResult: function (item) {
            return {
                id: item.baseIdentity.id,
                value: item.postalCode,
                text: item.postalCode + " " + item.townName,
                html: [item.postalCode, ' ', $('<b>').text(item.townName)
                ]
            };
        }
    }).on('autocomplete.select', function (evt, selectedTown) {
        const fld = $(this);
        fld.val(selectedTown.townName);
        const postalcodefld = $('[name="' + fld.attr('id').replace('.townName', '.postalCode') + '"]');
        postalcodefld.val(selectedTown.postalCode);
        checkField(postalcodefld);
        populateSuburbs(fld.attr('id'), selectedTown);
    }).change(function (event) {
 ??????
    }

(same for postal code)

After autoselect, i dont have to check data against database again, but when user enters PC "55112" and City "Mainz" (which dont exist), I have to fire an ajax to check pc/town with backend (on blur) this change fires BEFORE the autocomplete.select callback is called, cause the selection also fires onBlur.

Did I miss s.th. from the docs? I think this is a common scenario. Should I stopPropagate in preSearch or ... ?? I am a bit overwhelmed by the event model :-p

(This correlates also with #115, which I'd be happy to be implemented).

tante grazie, S.