Inject dynamic additional parameters to url #43
-
Hi, Is there any option to inject dynamic additional parameters to query string? For example:
I know it is possible to set initial parameters in
However, it will inject a static initial value or null/undefined if it is not set yet when you set up typeahead instance, if it changes it will not get updated. Any ideas? Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @SneakyGerald , Thank you for your comment. To pass more data via GET parameters, you can use a callback that returns a string. For example typeahead({
input: document.querySelector('.search'),
source: {
identifier: 'name',
remote: {
url: () => {
const token = window.token || ''; // get the necessary token
return `https://restcountries.com/v2/name/%QUERY/?token=${token}`
},
wildcard: '%QUERY',
},
},
highlight: true,
limit: 10
}) You can also pass more data using the requestOptions parameter of the remote/prefetch sources. (https://typeahead.digitalfortress.tech/#config?id=source) An example using a remote source is shown below for further clarity typeahead({
input: document.querySelector('.search'),
source: {
identifier: 'name',
remote: {
url: 'https://restcountries.com/v2/name/%QUERY',
wildcard: '%QUERY',
requestOptions: {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'Clark Kent' }),
},
},
},
highlight: true,
limit: 10
}) As per the above example, we pass additional data as a key-value pair ({ name: 'Clark Kent' }) Hope that helps! |
Beta Was this translation helpful? Give feedback.
Hello @SneakyGerald , Thank you for your comment.
To pass more data via GET parameters, you can use a callback that returns a string. For example
You can also pass more data using the requestOptions parameter of the remote/prefetch sources. (https://typeahead.digitalfortress.tech/#config?id=source)
An example using a remote source is shown …