2

I just need to set a default value (with readonly attribute) to the city field in the shipping address section. because the delivery is limited to a particular city at the moment.But the user is free to type any city name in billing address.

In the LayoutProcessor, getBillingAddressComponent() method i have added :

....

....

.... 

'city' => [
    'readonly' =>'readonly',
    'config' => [
    'value' =>'My Custom Value',
    'readonly' =>'readonly',
     'elementTmpl' => 'ui/form/element/textC',
        'tooltip' => [
            'description' => __('We deliver items only in selected cities at the moment.'),
        ],
    ],
],

....

....

TextC.html

<input class="admin__control-text" type="text" value="My Custom Value" readonly
data-bind="
    value: value,
    hasFocus: focused,
    valueUpdate: valueUpdate,
    attr: {
        name: inputName,
        placeholder: placeholder,
        'aria-describedby': noticeId,
        id: uid,
        disabled: disabled,
        maxlength: 255
        readonly: readonly
}"/>

Mean time i don't care about editing the core files. Iam working in Magento 2.2

Iam familiar with copying and editing templates in magento 1.X. But i can't find a way to achieve this in Magento 2. Im not sure that im in a right path.

1 Answer 1

0

Your HTML file seems valid, but in your layout processor you can try something like this

'city' => [
    'config' => [
        'readonly' =>true,
        'value' =>'My Custom Value',
        'elementTmpl' => 'ui/form/element/textC',
        'tooltip' => [
            'description' => __('We deliver items only in selected cities at the moment.'),
        ],
    ],
],

Passing boolean to readonly worked for me

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.