0

I want to add a new field to my shipping address section on checkout page, I was able to achieve it by below code.

<item name="shippingAddress" xsi:type="array">
    <item name="children" xsi:type="array">
        <item name="shipping-address-fieldset" xsi:type="array">
            <item name="children" xsi:type="array">
                <item name="location" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/form/element/abstract</item>
                    <item name="label" xsi:type="string">Location</item>
                    <item name="provider" xsi:type="string">checkoutProvider</item>
                    <item name="visible" xsi:type="string">true</item>
                    <item name="sortOrder" xsi:type="string">200</item>
                    <item name="config" xsi:type="array">
                        <item name="template" xsi:type="string">ui/form/field</item>
                        <item name="elementTmpl" xsi:type="string">ui/form/element/input</item>
                        <item name="tooltip" xsi:type="array">
                            <item name="description" xsi:type="string" translate="true">Search your location.</item>
                        </item>
                    </item>
                </item>
            </item>
        </item>
    </item>
</item>

The field is added to shipping address form but the name attribute is null. I need to set it as location but it always stays null. I have tried adding name and inputName attributes to xml but nothing seems to be working. Please check below as the html generated for my field.

<input class="input-text" type="text" data-bind="
    value: value,
    valueUpdate: 'keyup',
    hasFocus: focused,
    attr: {
        name: inputName,
        placeholder: placeholder,
        'aria-describedby': getDescriptionId(),
        'aria-required': required,
        'aria-invalid': error() ? true : 'false',
        id: uid,
        disabled: disabled
    }" name="" aria-invalid="false" id="YCYKNDR">

Do anyone have any idea how we can set name attribute for input field on shipping address section?

1 Answer 1

1

I think you should check the official Magento Docs to add a new field to checkout. Follow the docs to add the field so you can handle the data submission as well.

https://devdocs.magento.com/guides/v2.3/howdoi/checkout/checkout_new_field.html

The code you posted adds the field to checkout but you can't do much with it, it just renders it to the view.

2
  • Thank you Tsita for your answer. I have gone through magento devdocs as well as some other blogs but there is no configuration to set name in them. Jul 30, 2019 at 7:19
  • Try adding the field using the first step from the link i have provided instead of xml and see if the name attribute gets populated.
    – Tsita
    Jul 30, 2019 at 7:36

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.