A
A
Alexander Bulatov2019-01-18 20:16:53
Yii
Alexander Bulatov, 2019-01-18 20:16:53

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>",
            ],
        ]
    ]
]);

And actually how to add one more parameter. I must say right away that with such code, errors are pouring in the console.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
morricone85, 2019-01-18
@morricone85

what does this widget do?
so try:

Url::to(['site/matched-cities', 'query' => $query]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question