sergiodlopes / jquery-flexdatalist

Flexible input autocomplete/datalist plugin for jQuery
http://projects.sergiodinislopes.pt/flexdatalist/
MIT License
364 stars 84 forks source link

Be able to cancel event #98

Open clockworkmice opened 7 years ago

clockworkmice commented 7 years ago

I have a search that makes a remote API call to send in the value and this works fine.

People can search by location name or postcode. I was hoping to capture before:flexdatalist.search for example do some regex on the value and cancel the event if there is a match. With some basic attempts though I have been unable to cancel the search going to the remote API.

Maybe I am not doing this right, maybe there is a better event to handle or maybe cancelling this event isn't possible? I've tried handling before:flexdatalist.search before:flexdatalist.data and change:flexdatalist also jQuery change

$(".flexdatalist").flexdatalist({
    minLength: 3,
    url: "/property/search",
    keywordParamName: "locationName"
}).on("before:flexdatalist.search", function (event, data, options) {
    console.log(event);
    console.log(data);
    console.log(options);
    if (true) { // catch everything for testing
        event.stopPropagation();
        event.preventDefault();
        return false;
    }
});
sergiodlopes commented 7 years ago

Hi,

You would like to prevent sending search requests to the remote API? Hmm... maybe removing the url from options, setting options.url to null. This would certainly prevent the remote request.

Sérgio