Skip to main content
4 of 4
edited tags
Muhammad Hasham
  • 8.8k
  • 11
  • 51
  • 105

Magento 2 - Admin form Multi Select field issue

I added this code for Multi Select in my form.

File Path Should be like: app\code\Vendor\Module\Block\Adminhtml\Mpages\Edit\Tab\Main.php

$fieldset->addField(
            'categories',
            'multiselect',
            [
                'label' => __('Categories'),
                'title' => __('Categories'),
                'name' => 'categories',
                'required' => true,
                'options' => \Vendor\Module\Block\Adminhtml\Mpages\Grid::getValueArray7(),
                'disabled' => $isElementDisabled
            ]
        );

This is my getValueArray7() function in grid file.

static public function getValueArray7()
        {
            $data_array=array();
            foreach(\Vendor\Module\Block\Adminhtml\Mpages\Grid::getOptionArray7() as $k=>$v){
               $data_array[]=array('value'=>$k,'label'=>$v);        
            }
            return($data_array);

        }

It shows me empty multi select field.