Frage

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
            ]
        );
War es hilfreich?

Lösung

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
    ]
);

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top