From 4ad05570ca089b3a39807aa0b04d3e90cb183620 Mon Sep 17 00:00:00 2001 From: Bartek Igielski Date: Sun, 17 Sep 2017 14:16:00 +0200 Subject: [PATCH] Backport of changes in region component logic from deveop (2.2) --- .../Ui/view/base/web/js/form/element/region.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/form/element/region.js b/app/code/Magento/Ui/view/base/web/js/form/element/region.js index faac496251ac4..ff16f2370df28 100644 --- a/app/code/Magento/Ui/view/base/web/js/form/element/region.js +++ b/app/code/Magento/Ui/view/base/web/js/form/element/region.js @@ -24,6 +24,7 @@ define([ update: function (value) { var country = registry.get(this.parentName + '.' + 'country_id'), options = country.indexedOptions, + isRegionRequired, option; if (!value) { @@ -36,13 +37,21 @@ define([ this.validation['required-entry'] = false; this.required(false); } else { - if (!option['is_region_required']) { + if (option && !option['is_region_required']) { this.error(false); this.validation = _.omit(this.validation, 'required-entry'); } else { this.validation['required-entry'] = true; } + if (option && !this.options().length) { + registry.get(this.customName, function (input) { + isRegionRequired = !!option['is_region_required']; + input.validation['required-entry'] = isRegionRequired; + input.required(isRegionRequired); + }); + } + this.required(!!option['is_region_required']); } }, @@ -56,9 +65,11 @@ define([ */ filter: function (value, field) { var country = registry.get(this.parentName + '.' + 'country_id'), - option = country.indexedOptions[value]; + option; if (country) { + option = country.indexedOptions[value]; + this._super(value, field); if (option && option['is_region_visible'] === false) {