Reputation: 1923
I am using below code to initialise select2 on a select box. But the delay is not working, requests are going to server immediately.
$(".multi_select").select2({
multiple: true,
allowClear: true,
minimumInputLength: 2,
delay: 5000,
ajax: {
url: "/search.json",
dataType: 'json'
}
});
Another problem I am facing is, I am getting abort error on fast typing, that means previous requests are not getting aborted. Yesterday when I added above code, without delay, it was working fine without 'abort' error. Today, it gives abort error, with and without delay along with failure of delay.
I am using v4.0.3 and there is no change in project since yesterday so I don't understand that what happened suddenly.
Upvotes: 1
Views: 1412
Reputation: 17647
The delay parameter has to be added to ajax section:
$(".multi_select").select2({
multiple: true,
allowClear: true,
minimumInputLength: 2,
ajax: {
url: "/search.json",
dataType: 'json',
delay: 5000
}
});
See: https://select2.org/data-sources/ajax#rate-limiting-requests
Upvotes: 4