Is there anyway to add an uneditable field in magento 2 admin form?
-
07-04-2021 - |
题
IS there anyway to add an uneditable field in magento 2 admin form?
$fieldset->addField(
'giftcard_comment',
'textarea',
[
'label' => __('Comment'),
'title' => __('Comment'),
'name' => 'giftcard_comment',
'required' => false,
'editable' => false
]
);
解决方案
You can set true and false by param value using this below way :
$id = $this->getRequest()->getParam('id', false);
$fieldset->addField(
'giftcard_comment',
'textarea',
[
'label' => __('Comment'),
'title' => __('Comment'),
'name' => 'giftcard_comment',
'required' => false,
'readonly' => $id ? true : false
]
);
其他提示
Try 'readonly' => true
insted of 'editable' => false
$id = $this->getRequest()->getParam('id');
$fieldset->addField(
'giftcard_comment',
'textarea',
[
'label' => __('Comment'),
'title' => __('Comment'),
'name' => 'giftcard_comment',
'required' => false,
'readonly' => $id ? true : false
]
);
Hope this will help you.