Add 500ms delay before AJAX in Select2

We have four select2 Ajax pickers in `solidus_backend`:
- Option Value Picker
- Product Picker
- Taxon Autocomplete
- Variant Autocomplete

The Variant autocomplete already has a 500ms delay between the user
finishing typing and the Ajax request firing. This is good, because it
stops requests happening at every keypress. This commit extends that
behavior to the option value, product and taxon pickers.
This commit is contained in:
Martin Meyerhoff 2025-05-21 10:42:08 +02:00
parent 0ba073802f
commit 4eec4797fa
3 changed files with 3 additions and 0 deletions

View File

@ -23,6 +23,7 @@ $.fn.optionValueAutocomplete = function (options) {
},
ajax: {
url: Spree.pathFor('api/option_values'),
quietMillis: 500,
datatype: 'json',
data: function (term, page) {
var productId = typeof(productSelect) !== 'undefined' ? $(productSelect).select2('val') : null;

View File

@ -35,6 +35,7 @@ $.fn.productAutocomplete = function (options) {
this.select2({
minimumInputLength: 3,
multiple: multiple,
quietMillis: 500,
initSelection: function (element, callback) {
$.get(Spree.pathFor('admin/search/products'), {
ids: element.val().split(','),

View File

@ -47,6 +47,7 @@ $.fn.taxonAutocomplete = function (options) {
},
ajax: {
url: Spree.pathFor('api/taxons'),
quietMillis: 500,
datatype: 'json',
data: function (term, page) {
return {