سؤال

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.

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى magento.stackexchange
scroll top