I am trying to disable the text field in the configuration field once admin has entered the data. I know it can be done via <frontend_model> but in that case the field gets disabled as soon as the page loads.

frontend_model class:

protected function _getElementHtml(AbstractElement $element): string
        $element->setData('readonly', 1);
        return $element->getElementHtml();

So, how can I disable it after the admin has entered value and saves configuration?

2 Answers 2


You can try this one :

public function _getElementHtml(
        \Magento\Framework\Data\Form\Element\AbstractElement $element
    ) {
         * Magento\Framework\App\Config\ScopeConfigInterface;
        $value = $this->scopeConfigManager->getValue('section_id/group_id/field_id');
        if (!empty($value)) {
            $element->setData('readonly', true);
        return parent::_getElementHtml($element);

In this way we can disable it after the admin has entered value and saves configuration.


There is another way to make the system configuration field read-only by setting filed value from app/etc/config.php

For example, is an example of how to set the title of the "Check / Money Order" payment method from the config.php

return [
        'modules' => [
            .... // your native/default magento code here
        'system' => [
            'default' => [
                'payment' => [
                    'checkmo' => [
                        'title' => 'Check / Money order'

This is how you can set the value of each configuration value and this is can not be editable from the admin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.