This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
lucas.sanner54070
In my plugin I set up a button displaying a category list in a popup.
class Books extends Controller
{
public $implement = [
'Backend.Behaviors.FormController',
'Backend.Behaviors.ListController',
];
public $formConfig = 'config_form.yaml';
public $listConfig = 'config_list.yaml';
public $listWidget = null;
public $searchWidget = null;
public function __construct()
{
parent::__construct();
$this->createSearchWidget();
$this->createListWidget();
}
...
public function createSearchWidget()
{
$config = ['prompt' => 'backend::lang.list.search_prompt'];
$this->searchWidget = $this->makeWidget('Backend\Widgets\Search', $config);
$this->searchWidget->bindToController();
}
public function createListWidget()
{
$config = $this->makeConfig('$/codalia/bookend/models/category/columns.yaml');
$config->model = new \Codalia\Bookend\Models\Category;
$config->recordsPerPage = 10;
$config->showPageNumbers = true;
$config->recordOnClick = 'selectCategoryItem(:id, \':name\');';
$this->listWidget = $this->makeWidget('Backend\Widgets\Lists', $config);
$this->listWidget->bindToController();
}
public function onLoadCategoryList()
{
$this->vars['search'] = $this->searchWidget;
$this->vars['modelList'] = $this->listWidget;
return $this->makePartial('modal_category');
}
...
}
in my partial:
<?= $search->render() ?>
<?= $modelList->render() ?>
So far so good, both the category list and the search box are displayed in my modal window.
But when I type something in the search box, the list is not filtered.
What can I do to connect the 2 widgets in order to have the searched word taken into account in the category list query ?
lucas.sanner54070
Good call ! The solution lies in the makeList() method.
It just needs to use the bindEvent() method.
public function createSearchWidget()
{
$config = ['prompt' => 'backend::lang.list.search_prompt'];
$this->searchWidget = $this->makeWidget('Backend\Widgets\Search', $config);
$this->searchWidget->bindToController();
/*
* Link the Search Widget to the List Widget
*/
$this->searchWidget->bindEvent('search.submit', function () {
$this->listWidget->setSearchTerm($this->searchWidget->getActiveTerm(), true);
return $this->listWidget->onRefresh();
});
}
1-3 of 3