Answer the question
In order to leave comments, you need to log in
Smart search, data in the field is not displayed?
Hello everyone, help with smart search or live search, the problem is this, after I start typing product names in the input field, the products found are displayed, but after I have selected the product, nothing is displayed in the search field, it’s just empty and when I send it by post to the controller in order to show the user what he found, then $ _POST is empty (((
main
<?php $template = '<div><span style="margin-right: 20px"><img style="width: 35px" src="{{srs}}"></span><span>{{title}}</span> <span style="background: #fef200;color: #000;font-weight: bold;padding: 4px">{{price}} грн.</span></div>'; ?>
<?= Typeahead::widget([
'name' => 'product',
'options' => ['placeholder' => 'Поиск товаров'],
'pluginOptions' => ['highlight' => true],
'dataset' => [
[
'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
'display' => 'value',
//'prefetch' => $baseUrl . '/samples/countries.json',
'remote' => [
'url' => Url::to(['/search/product-list']) . '?q=%QUERY',
'wildcard' => '%QUERY'
],
'templates' => [
'notFound' => '<div class="text-danger" style="padding:0 8px">Ничего не найдено.</div>',
'suggestion' => new \yii\web\JsExpression("Handlebars.compile('{$template}')")
]
]
],
]) ?>
public function actionProductList($q = null)
{
$query = Product::find()
->where('title LIKE "%' . $q . '%"')
->orderBy('title');
$out = [];
foreach ($query->all() as $d) {
/**
* @var $d Product
* @var $image ObjectFile
*/
$image = ObjectFile::find()
->where(['id' => $d->img_id])
->one();
$srs = null;
if ($image) {
$srs = '/web/uploads/products/' . Product::getImageName($image->id);
}
$out[] = [
'title' => $d->title,
'srs' => $srs,
'price' => $d->price
];
}
echo Json::encode($out);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question