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

Detect click on noSuggestion

Open Mushr0000m opened this issue 8 years ago • 2 comments

Hi,

Is there a way to make the noSuggestionNotice selectable/clickable and have a callback ? The aim is to display "Create a new tag" for exemple so the user can select it and I can call a callback to handle new tag creation.

Right now I'm using transformResult and onSelect to create a fake result, but it would be nice and in my opinion make sens to able to use this noSuggestionNotice param to do so.

Thanks

Mushr0000m avatar Sep 15 '17 09:09 Mushr0000m

After posting my question (with similar problem) to stack overflow( https://stackoverflow.com/questions/48973057/devbridge-autocomplete-howto-empty-search-field ) I found Your question. It seems, we're pointing in the same direction... I made another way: my AJAX route for getting the data from database sends also something like "make a new tag"- but my problem is the text in the searchfield stays the same... Could you explain how you "solved" or "bypassed" your problem with transformResult and onSelect? Thanks!

sneakyx avatar Feb 25 '18 11:02 sneakyx

No problem, this is my approach :

transformResult: function (response, originalQuery) {
    var suggestions = [];
    response.data.forEach(function(item) {
        suggestions.push({ value: item.name, data: item });
    });

    if (originalQuery.length > 1) {
        suggestions.push({ value: originalQuery, data: null });
    }

    return { suggestions };
},
formatResult: function (suggestion, currentValue) {
    if (suggestion.data === null) {
        return "Create a new tag";
    }
    return suggestion.value;
},

Mushr0000m avatar Feb 25 '18 18:02 Mushr0000m