Magento – Magento 2 how to add city dropdown

addressdropdown-attributemagento-2.1

i am trying to city as dropdown in only checkout page with following script in Magento\Checkout\Block\Cart\LayoutProcessor.php

$elements = [
        'city' => [
            'visible' => true,
            'formElement' => 'select',
            'label' => __('City'),
            'options' => [
                [
                    'value' => '',
                    'label' => 'Please Select',
                ],
                [
                    'value' => '1',
                    'label' => 'First Option',
                ]
            ],
            'value' =>  null
        ],
        'country_id' => [
            'visible' => true,
            'formElement' => 'select',
            'label' => __('Country'),
            'options' => [],
            'value' => null
        ],
        'region_id' => [
            'visible' => true,
            'formElement' => 'select',
            'label' => __('State/Province'),
            'options' => [],
            'value' => null
        ],
        'postcode' => [
            'visible' => true,
            'formElement' => 'input',
            'label' => __('Zip/Postal Code'),
            'value' => null
        ]
    ];

but still it's showing as input text filed. Any one can please suggest best solution

Best Answer

You are working on wrong layoutProcessor. Please, read this documentation which will explain you how to modify existing field on checkout: http://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_new_field.html

You should register your own layoutProcessor and modify layout array or, for tests purpose, you can modify vendor/magento/module-checkout/Block/Checkout/LayoutProcessor.php which is the proper class to work with.

Related Topic