From f76db61364f8a292197b6ee2bf9685b1c8dc2b0b Mon Sep 17 00:00:00 2001 From: Sohail Nasir Date: Fri, 28 Apr 2017 21:16:33 +0100 Subject: [PATCH] unable to access params term when loading via Ajax When trying to use Select2 v4, I was unable to get the term from the search box as the params was declared as a string --- types/select2/index.d.ts | 1 + types/select2/select2-tests.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/types/select2/index.d.ts b/types/select2/index.d.ts index ad67108906..5828dba2e9 100644 --- a/types/select2/index.d.ts +++ b/types/select2/index.d.ts @@ -26,6 +26,7 @@ interface Select2AjaxOptions { dataType?: string; delay?: number; cache?: boolean; + data?: (params: Select2QueryOptions, page: number, context: any) => any; results?: (term: any, page: number, context: any) => any; processResults?:(data: any, params: any) => any; } diff --git a/types/select2/select2-tests.ts b/types/select2/select2-tests.ts index 9fd6be0a93..9f9f8f3732 100644 --- a/types/select2/select2-tests.ts +++ b/types/select2/select2-tests.ts @@ -58,7 +58,9 @@ $("#e6").select2({ url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json", dataType: 'jsonp', cache: false, + data: function (params, page) { return { + q: params.term, page_limit: 10, apikey: "ju6z9mjyajq2djue3gbvv26t" }; @@ -77,7 +79,9 @@ $("#e6").select2({ ajax: { url: () => { return "http://api.rottentomatoes.com/api/public/v1.0/movies.json"; }, dataType: 'jsonp', + data: function (params, page) { return { + q: params.term, page_limit: 10, apikey: "ju6z9mjyajq2djue3gbvv26t" }; @@ -97,7 +101,9 @@ $("#e7").select2({ url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json", dataType: 'jsonp', delay: 100, + data: function (params, page) { return { + q: params.term, page_limit: 10, page: page, apikey: "ju6z9mjyajq2djue3gbvv26t"