Jump to content

[SOLVED] HelperList filter reset not working


Recommended Posts

Hi, I have problem with a HelperList filter reset. On a form with a list created via HelperList

    $helper                 = new HelperList();
    $helper->identifier     = 'id_product';
    $helper->table_id       = 'js-product-list';
    $helper->title          = 'ProductList';
    $helper->table          = $table_name;
    $helper->simple_header  = false;
    $helper->shopLinkType   = '';
    $helper->token          = Tools::getAdminTokenLite('AdminModules');
    $helper->imageType      = 'jpg';
    $helper->currentIndex   = AdminController::$currentIndex.'&configure='.$this->name;
    $helper->no_link        = false; 

I use filters which work fine, but the button supposed to reset the filter just behaves the same way as the actual submit buton - submits the filters.

On click, the page reloads and the submitReset*** parameter is being set correctly. From what I found out, the reset should be functional by itself, with no need to program anything else. Other "prestashop native" lists work fine and the only difference I spotted is the fact, that after clicking on the "working" reset button, the "network" console in the browser shows, that the page is being loaded twice - once with the submitReset*** parameter set and then redirected with HTTP code 302 and loaded second time with filtering parameters unset. The mine one loads only once. No redirection happens. Can someone please help me to find the cause?

Link to comment
Share on other sites

Ok, the helperList inside a Module::getContent() is not a good idea because submitReset are handled in AdminController::initProcess(), when you are in a Module::getContent() your assignment of list is done after AdminController::init() so it's not working.

You should create an ModuleAdminController to access all useful method available for helpers.

I don't use Module::getContent() anymore in my modules, in fact I just use it to make a redirection to my ModuleAdminController.

If you use an helperList inside a Module::getContent() you cannot use advanced features of this helper which is designed to be used in an AdminController, usage in Module::getContent() is tricky, I think it's a bad practice.

Did you know how to create an ModuleAdminController ?

  • Like 1
Link to comment
Share on other sites

@JanettI see. Thank you. I have a basic idea how to create a new contoller, like where to place the file, that it is going to be a new class extending ModuleAdminController etc. But If you could recommend me any guide or give me some tips, I will be glad. Thanks!

 

Link to comment
Share on other sites

So you need an ObjectModel too.

I'm I only find good example for 1.7+, I am not fine with example I find for 1.5/1.6 example.

I will try to do it, can you please tell me if you need to use multilang fields or multishop in your module ?

Link to comment
Share on other sites

@Janett, I must be doing something wrong. I created a new controller that extends ModuleAdminController, Module::GetContent() is redirecting to it, the content is being handled by the new controller and displayed on a new admin tab, but unfortunatelly, the behavior is 100% same. Everything works, but the filter reset button.

Link to comment
Share on other sites

You should declare $this->fields_list inside constructor. You can see for example https://github.com/PrestaShop/PrestaShop/blob/develop/controllers/admin/AdminGendersController.php

if you don’t do it inside the constructor, AdminController::init() doesn’t have data to make AdminController::initProcess() and initialization of SubmitReset***

Same for $this->fields_options for HelperOption et $this->fields_form for HelperForm. They must be declared inside constructor.

Its a common mistake to do it inside renderList() or renderForm() or renderOptions()

You also have to declare in constructor $this->table and $this->className (name of your ObjectModel)

Link to comment
Share on other sites

@Janett, thank you for your advices. It turned out, that my assumption, that the reset action doesn't need any further programing and that it works "out of box" was wrong. The solution is simple:

        if (Tools::isSubmit('submitReset'.$this->table_name))
        {
            Tools::redirectAdmin($this->context->link->getAdminLink('AdminTag'));
        } 

... in the InitContent() function of my controller

Link to comment
Share on other sites

  • Matt75 locked this topic
Guest
This topic is now closed to further replies.
×
×
  • Create New...