Skip to content

Commit

Permalink
feat(pat-select2): Add ajaxTimeout option to configure the time to wa…
Browse files Browse the repository at this point in the history
…it before ajax requests are done.
  • Loading branch information
thet committed Feb 9, 2023
1 parent 5588e96 commit cd1d491
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/pat/select2/select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default Base.extend({
parser: "mockup",
defaults: {
separator: ",",
ajaxTimeout: 300,
},

initializeValues() {
Expand Down Expand Up @@ -196,9 +197,12 @@ export default Base.extend({
}

let queryTerm = "";

const ajaxTimeout = parseInt(this.options.ajaxTimeout || 300, 10);
delete this.options.ajaxTimeout;
this.options.ajax = $.extend(
{
quietMillis: 300,
quietMillis: ajaxTimeout,
data: (term, page) => {
queryTerm = term;
return {
Expand Down
26 changes: 19 additions & 7 deletions src/pat/select2/select2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import registry from "@patternslib/patternslib/src/core/registry";
import utils from "@patternslib/patternslib/src/core/utils";
import "select2";

const SELECT2_TIMEOUT = 500;
const SELECT2_TIMEOUT = 1;

describe("Select2", function () {
let ajax_defaults_transport = null;
Expand Down Expand Up @@ -106,7 +106,9 @@ describe("Select2", function () {
class="pat-select2"
data-pat-select2="placeholder:Search for a Value;
vocabularyUrl: /select2-ajax.json;
width:20em" />
width:20em;
ajaxTimeout: 1;
" />
`;
registry.scan(document.body);
await utils.timeout(1);
Expand All @@ -129,7 +131,9 @@ describe("Select2", function () {
class="pat-select2"
data-pat-select2="placeholder:Search for a Value;
vocabularyUrl: /select2-ajax.json;
width:20em" />
width:20em;
ajaxTimeout: 1;
" />
`;
registry.scan(document.body);
await utils.timeout(1);
Expand All @@ -151,7 +155,9 @@ describe("Select2", function () {
<input type="hidden" class="pat-select2"
data-pat-select2="placeholder:Search for a Value;
vocabularyUrl: /select2-ajax.json;
width:20em" />
width:20em;
ajaxTimeout: 1;
" />
`;
registry.scan(document.body);
await utils.timeout(1);
Expand All @@ -174,7 +180,9 @@ describe("Select2", function () {
class="pat-select2"
data-pat-select2="placeholder:Search for a Value;
vocabularyUrl: /select2-ajax.json;
width:20em" />
width:20em;
ajaxTimeout: 1;
" />
`;
registry.scan(document.body);
await utils.timeout(1);
Expand Down Expand Up @@ -255,7 +263,9 @@ describe("Select2", function () {
class="pat-select2"
data-pat-select2="tags: Red,Yellow,Blue;
allowNewItems: false;
width:20em" />
width:20em;
ajaxTimeout: 1;
" />
`;
registry.scan(document.body);
await utils.timeout(1);
Expand All @@ -278,7 +288,9 @@ describe("Select2", function () {
<input type="hidden" class="pat-select2"
data-pat-select2="vocabularyUrl: /select2-ajax.json;
allowNewItems: false;
width:20em" />
width:20em;
ajaxTimeout: 1;
" />
`;
registry.scan(document.body);
await utils.timeout(1);
Expand Down

0 comments on commit cd1d491

Please sign in to comment.