Skip to content

Commit 6aa89ef

Browse files
committed
MAGETWO-34253: CLONE - Postal code is still mandatory for Non-US addresses that don't use it
- Fixed issue with async component initialization
1 parent 410bc0b commit 6aa89ef

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

app/code/Magento/Ui/view/base/web/js/form/element/post-code-fix.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ define([
1111

1212
return Abstract.extend({
1313
/**
14+
* Extended list of Listeners
15+
*
1416
* @return {this}
1517
*/
1618
initListeners: function(){
@@ -21,26 +23,40 @@ define([
2123
return this;
2224
},
2325

26+
/**
27+
* Fix _postcode_ depend on _country_id_ change:
28+
* - If country in list "Zip/Postal Code is Optional countries" then
29+
* - field "postcode" should not be required
30+
*
31+
* @returns {this}
32+
*/
2433
update: function(){
2534
var parentScope = this.getPart(this.getPart(this.name, -2), -2),
26-
countryComponent = registry.get(parentScope + '.country_id.0'),
27-
value = countryComponent.value(),
28-
element;
29-
30-
countryComponent
31-
.options()
32-
.some(function (el) {
33-
element = el;
34-
return el.value === value;
35-
});
36-
37-
if(!element.is_region_required) {
38-
this.error(false);
39-
this.validation = _.omit(this.validation, 'required-entry');
40-
} else {
41-
this.validation['required-entry'] = true;
42-
}
43-
this.required(!!element.is_region_required);
35+
option,
36+
postcode = this;
37+
38+
registry.get(parentScope + '.country_id.0', function (countryComponent) {
39+
var value = countryComponent.value();
40+
41+
if (!value) { // empty value discard logic
42+
return;
43+
}
44+
45+
countryComponent
46+
.options()
47+
.some(function (el) {
48+
option = el;
49+
return el.value === value;
50+
});
51+
52+
if(!option.is_region_required) {
53+
postcode.error(false);
54+
postcode.validation = _.omit(postcode.validation, 'required-entry');
55+
} else {
56+
postcode.validation['required-entry'] = true;
57+
}
58+
postcode.required(!!option.is_region_required);
59+
});
4460

4561
return this;
4662
}

0 commit comments

Comments
 (0)