4

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.

6

I also faced this problem, You just need to replace your multi select field code in main.php with this. What I did, I added the values instead of options

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

I hope this will help

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.