Magento2: "Customer > Address > State/Province" in admin backend does not honour the "State is Required for" setting, is always required

Created on 21 Aug 2016  路  17Comments  路  Source: magento/magento2

the "State/Province" (attribute region_id) selectbox in "Customers > Customer > {edit} > Addresses" is always marked as "required" when the selected country has states - even when the option "State is Required for" in "Stores > Configuration > General > State Options" is not enabled for this country.

this prevents saving the customer.

Preconditions

  1. CE 2.1.0

    Steps to reproduce

  2. in "Stores > Configuration > General > Country Options" enable a country that has regions/states, we'll use "Switzerland" for the rest of the steps.

  3. in "Stores > Configuration > General > State Options" ensure option "State is Required for" is not enabled for "Switzerland"
  4. save, clear config cache
  5. create or edit a customer, add or edit this customers address
  6. select "Country: Switzerland"

    Expected result

  7. The "State/Province" selectbox is popuplated and not mandatory

    Actual result

  8. The "State/Province" selectbox is popuplated and marked as required

Customer Format is valid Ready for Work bug report

Most helpful comment

I think the test case was not properly followed as it is reproducible in a 2.1.5 installation.

heck, even the latest development code has still the bogus <item name="required-entry" xsi:type="boolean">true</item> validation on the region_id field.

All 17 comments

in www/vendor/magento/module-customer/view/base/ui_component/customer_form.xml the region_id is marked with an unconditional required validator:

        <field name="region_id">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">select</item>
                    <item name="source" xsi:type="string">address</item>
                    <item name="customEntry" xsi:type="string">region</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                    <item name="filterBy" xsi:type="array">
                        <item name="target" xsi:type="string">${ $.provider }:${ $.parentScope }.country_id</item>
                        <item name="field" xsi:type="string">country_id</item>
                    </item>
                </item>
            </argument>
        </field>

removing this validator "fixes" the issue - obviously the region is then also not required for countries where no "State is Required for" opt-out exists.

Hi! This is a known issue, internal ticket MAGETWO-56962. Thanks for reporting

thank you for the update!

problem seems still present in 2.1.1

@heldchen
Hi, i want to remove the validation. Can i override the customer_form.xml with a module?
I tried some possibilities, but with no success. I don't find something about overriding ui components of adminhtml.

@rzwinge unfortunately there does not seem to be a way to remove stuff from ui components in the adminhtml (in the frontend, you can manipulate it through an observer, but even that seems rather questionable).

you _can_ hack it with a plugin on \Magento\Framework\View\Layout\Generator\Structure::generate() and manipulate the $data array, but it is quite ... erhm ... unorthodox. that said, I have successfully used such a plugin to move around and remove some ui components in the adminhtml.

for this issue, I ended up creating a core patch for our installations until this is fixed in the source.

@heldchen Thank you for your hint. Then i backup the file and change it in the core.

still happening in 2.1.2 as well.

Also when i try to remove the default countries (Austria, Brazil, Canada, Estonia, Finland, Latvia, Lithuania, Romania, Spain, Switzerland and United States) from State Options in Congig -> General -> General it says You saved the configuration. but the options are still selected?

To the official support team of Magento: any idea of when this bug will be fixed?

this issue is still present in 2.1.4

We're experiencing this issue after upgrading to 2.1.5, can we have some confirmation of when this will be fixed in the core? This is a fairly big issue for us as we have a number of international customers and we're unable to correctly save their details.

Hello everyone,

I have made a Module, which provides a temporary fix for this Problem:
https://github.com/EliasKotlyar/RegionFix

Greetings
Elias

@sma09sjb, @EliasKotlyar just validated on fresh installation for 2.1.5 and 2.2-develop, and it test case is not reproducible.

I think the test case was not properly followed as it is reproducible in a 2.1.5 installation.

heck, even the latest development code has still the bogus <item name="required-entry" xsi:type="boolean">true</item> validation on the region_id field.

This bug reproduces in 2.1.9.

I am facing the same issue in Magento 2.1.7 and 2.1.9.
Also I could see in www/vendor/magento/module-customer/view/base/ui_component/customer_form.xml




text
select
address
region

true


${ $.provider }:${ $.parentScope}.country_id
country_id



The validation is always true.

Still present in 2.2.6.

Was this page helpful?
0 / 5 - 0 ratings