Answer the question
In order to leave comments, you need to log in
How to add an extra GET parameter to a request?
Good day!
Situation:
There is a kartik\typeahead\Typeahead widget and you need to dynamically add one more GET parameter
Data:
There is a code
echo Typeahead::widget([
'id' => 'current-city',
'name' => 'location-city',
'value' => $currentCity,
'options' => ['placeholder' => Yii::t('kupdam', 'Выберите из выпадающего списка при наборе текста')],
'scrollable' => true,
'pluginOptions' => ['highlight' => true],
'dataset' => [
[
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
'display' => 'value',
//'prefetch' => $baseUrl . '/samples/countries.json',
'remote' => [
'url' => Url::to(['site/matched-cities']) . '?q=%QUERY&p=%PARENT',
'prepare' => new \yii\web\JsExpression(''
. 'function(query, settings) {'
. 'let prepareQuery = settings.url.replace("%QUERY", query);'
. 'let selectedCountry = document.querySelector("#current-country").value;'
. 'let prepared = prepareQuery.replace("%PARENT", selectedCountry);'
. 'return prepared;'
. '}'),
// 'wildcard' => '%QUERY'
],
'templates' => [
'notFound' => "<div class='text-danger' style='padding: 0 8px'> $this->message </div>",
],
]
]
]);
Answer the question
In order to leave comments, you need to log in
what does this widget do?
so try:
Url::to(['site/matched-cities', 'query' => $query]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question