1

We use the default customer Show Prefix method. This works fine on the frontend.

But in the admin panel, the prefix in the customer is displayed as a input open text field, not as a dropdown with the options displayed.

For some reason the prefix in the admin panel is not displayed well.

How can we solve this?

enter image description here

enter image description here

3
+50

You will need to extends/customise the forms that are used in the backend to render the customer's forms.

for instance, customer_address_form.xml may be customised with:

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd" component="Magento_Customer/js/form/components/form">
    <fieldset name="general">
        <field name="prefix" sortOrder="10" formElement="select">
            <formElements>
                <select>
                    <settings>
                        <options class="Mbs\PrefixBecomesSelect\Model\Config\PrefixOptions"/>
                    </settings>
                </select>
            </formElements>
        </field>
    </fieldset>
</form>

and customer_form.xml customised with:

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="customer">
        <field name="prefix" formElement="select">
            <formElements>
                <select>
                    <settings>
                        <options class="Mbs\PrefixBecomesSelect\Model\Config\PrefixOptions"/>
                    </settings>
                </select>
            </formElements>
        </field>
    </fieldset>
</form>

the Model used in these customisation like below:

<?php

namespace Mbs\PrefixBecomesSelect\Model\Config;

class PrefixOptions implements \Magento\Framework\Data\OptionSourceInterface
{
    /**
     * @var \Magento\Customer\Model\Options
     */
    private $options;

    public function __construct(
        \Magento\Customer\Model\Options $options
    ) {
        $this->options = $options;
    }

    /**
     * @return array
     */
    public function toOptionArray()
    {
        $rawOptions = $this->options->getNamePrefixOptions();

        $options[] = ['value' => '', 'label' => '-'];

        foreach ($rawOptions as $label => $value) {
            $options[] = ['value' => $value, 'label' => $label];
        }

        return $options;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.