Add a Textarea to Shipping Address in Magento 2

checkoutmagento-2.1magento2ordersshipping-address

I followed this tutorial to add a new field to checkout:
http://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_new_field.html

Problem is: as long as it is a <input type="text" /> everything works. But if I change my input field to a <textarea> it won't save.

I highly suspect Magento guys just don't know about textareas…

Well on a serious note, I found code handling textareas but couldn't find code that handles textareas in checkout. Also I didn't find any implementation of a textarea in magento.

Has anyone figured how to do it? (or if it is possible at all)

Best Answer

Yes it's possible to add textarea to the shipping address on checkout. I just added a delivery comment field which is a textarea.

In your LayoutProcessor plugin you should declare the field like this:

'delivery_comment' => [
    'component' => 'Magento_Ui/js/form/element/textarea',
    'config' => [
        'customScope' => 'shippingAddress',
        'template' => 'ui/form/field',
        'options' => [],
    ],
    'dataScope' => 'shippingAddress.delivery_comment',
    'label' => __('Delivery Comment'),
    'provider' => 'checkoutProvider',
    'visible' => true,
    'validation' => false,
    'sortOrder' => 250,
]

How do you handle the saving of this data to the quote and order models? Did you follow the tutorial?

I think that you need to observe the sales_model_service_quote_submit_before event and copy the field from quote to order object.