0

I am converting the searchbar in one of my components to JLayout Search Tools searchbars to become more ready for J!4. Everything is working fine but it is not populating the filters.

In view.html.php I have this:

 $this->state = $this->get('State'); $this->filterForm = $this->get('FilterForm'); $this->activeFilters = $this->get('ActiveFilters'); if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors), 500); } 

$this->state / $this->filterForm / $this->ActiveFilters are populated.

In my filter_categories.xml file I have this:

<?xml version="1.0" encoding="utf-8"?> <form> <fields name="filter"> <field name="search" type="text" label="Search" hint="Filter" /> <field name="published" type="list" label="COM_CONTENT_FILTER_PUBLISHED" description="COM_CONTENT_FILTER_PUBLISHED_DESC" onchange="this.form.submit();" > <option value="">Select Publishing State</option> <option value="1">Published</option> <option value="0">Unpublished</option> </field> </fields> <fields name="list"> <field name="limit" type="limitbox" class="input-mini" default="25" label="COM_CONTENT_LIST_LIMIT" description="COM_CONTENT_LIST_LIMIT_DESC" onchange="this.form.submit();" /> </fields> </form> 

Then in the model I have:

function __construct($config = []) { if (empty($config['filter_fields'])) { $config['filter_fields'] = [ 'published', 'a.published', 'search', 'a.search', ]; } parent::__construct($config); $app = JFactory::getApplication(); $start = $this->getState('list.start', $app->getUserStateFromRequest('limitstart', 'limitstart', 0, 'int')); $limit = $this->getState('list.limit', JFactory::getApplication()->get('list_limit')); $total = $this->getTotal(); if ($start > $total - $limit) { $start = max(0, (int) (ceil($total / $limit) - 1) * $limit); } $this->setState('list.start', $start); $this->setState('list.limit', $limit); $cid = $app->input->get('cid', [0], 'array'); $this->id = (int) $cid[0]; } protected function populateState($ordering = null, $direction = null) { $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); $this->setState('filter.search', $search); $state = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published'); $this->setState('filter.state', $state); $limit = $this->getUserStateFromRequest($this->context . '.filter.limit', 'filter_limit', ''); $this->setState('filter.limit', $limit); parent::populateState('a.id', 'asc'); } protected function getStoreId($id = '') { // Compile the store id. $id .= ':' . $this->getState('filter.search'); $id .= ':' . $this->getState('filter.published'); return parent::getStoreId($id); } 

Filters works like a charm, and it is filtering as expected. But when the users comes back in the page after filtering the search is for example empty.

As you can see in the screenshot, I have searched for Easy, one result (which is correct is being returned) Everything looks OK. But the search input box in the middle is empty after using the filter. Also the publishing is not set to the correct option.

enter image description here

2
  • This page seems related, but I don't think it contains a solution for you. stackoverflow.com/q/24388406/2943403 I'm only adding it in case it could help trigger new ideas. Commented Apr 11, 2019 at 22:53
  • This is something different than my question. Not problem, thank you for thinking with me. Commented Apr 14, 2019 at 14:59

1 Answer 1

0

Could you change view.html.php to:

$model = $this->getModel(); $this->items = $model->getItems(); $this->filterForm = $model->getFilterForm(); $this->activeFilters = $model->getActiveFilters(); $this->state = $model->getState(); $this->pagination = $model->getPagination(); 

And regarding your model: which Joomla Class do you extend? ListModel?

1
  • This is also not working :( I am using the JModelList Commented Apr 14, 2019 at 15:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.