1

I have created a custom customer attribute that shows up on the checkout page. I am trying to make this read only. That is show a value in the text field but not have it be editable. I tried adding the following parameter

 'readonly' => true,
  'value' => 'xxxx'

to my addattribute script. I did not get an error when i ran the script and the attribute was added. I see the field in my checkout form and xxxx shows up correctly but it is not read only, I can still edit the field. Does anyone know how to make the text field not editable?

1 Answer 1

1

1) If you want it to be read-only in magento forms, you can change its input type to 'label', as mentioned in this SO answer: https://magento.stackexchange.com/a/79465/22620

2) On a side note: If you want to show attribute only in backend, but not in frontends forms, use similar code in your attribute installer:

$attributeCode = 'my_custom_attribute';
$used_in_forms = array("adminhtml_customer"); // Only show in admin panel

$attribute = Mage::getSingleton("eav/config")->getAttribute("customer", $attributeCode);
$attribute
    ->setData("used_in_forms", $used_in_forms)
    ->setData("is_used_for_customer_segment", true)
    ->setData("is_visible", 0) // Hide on frontend
    ;

$attribute->save();
1
  • Just reporting that we are on 2.4.6-p3 and this does not work. There is no definition data for formElement label so the page crashes when componentData is null instead of array while constructing the ui_component
    – Jacques
    Dec 12, 2023 at 9:41

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.