A “Category Chooser” in Magento 2 Backend

A “Category chooser” in Magento 2 backend

Let’s imagine, you need to create a category chooser for magento admin panel. For example, this might be necessary in the following cases:

1. To be used for some standard form as follows:

2. For some backend configurations:

3. Or, like in my case, for some widgets:

So, let’s consider how it is possible to arrange that. Magento source code offers us several solutions but we have selected the simplest one to use. First off, we write down the code for the element itself:

But that is only a form’s input. Now, let’s write down some html and javascript code to output the chooser in the backend and let it perform properly:

So, this is the Multi Category Chooser. But what if we need only one category? For such case there is a ready-made solution available, so we do not need to invent anything new:

This solution I have applied for one of my widgets, but it is also possible to adapt it for configuring various form elements.



Post a new comment