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.

许可以下: CC-BY-SA归因
scroll top