1

Using magento 2.2, admin, customer -> all customer [Edit Panel]. I want to change ZIP control from text-field to select-list.

enter image description here

1 Answer 1

1

app/code/SR/Stackexchange/view/adminhtml/ui_component/customer_listing.xml


<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <columns name="customer_columns">
        <column name="billing_postcode" component="Magento_Ui/js/grid/columns/select" sortOrder="70">
            <settings>
                <options class="SR\Stackexchange\Model\Source\Postcode"/>
                <filter>select</filter>
                <editor>
                    <editorType>select</editorType>
                </editor>
                <dataType>select</dataType>
                <label translate="true">ZIP</label>
            </settings>
        </column>
    </columns>
</listing>

app/code/SR/Stackexchange/Model/Source/Postcode.php


<?php
namespace SR\Stackexchange\Model\Source;

use Magento\Framework\Data\OptionSourceInterface;

class Postcode implements OptionSourceInterface
{
    /**
     * @var array
     */
    protected $options;

    /**
     * Get options
     *
     * @return array
     */
    public function toOptionArray()
    {
        if ($this->options !== null) {
            return $this->options;
        }

        $options[] = [
            'label' => '90034',
            'value' => '90034',
        ];
        $options[] = [
            'label' => '90035',
            'value' => '90035',
        ];
        $options[] = [
            'label' => '49628-7978',
            'value' => '49628-7978',
        ];
        $this->options = $options;

        return $this->options;
    }
}

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.