Magento 2 - Admin form Multi Select field issue
-
27-02-2021 - |
سؤال
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
لا تنتمي إلى magento.stackexchange