Skip to content

Commit d1125a1

Browse files
author
Oleksii Korshenko
authored
Merge pull request #318 from magento-fearless-kiwis/FearlessKiwis-MAGETWO-56962-State-province-not-required-2.1
Fixed issue: - MAGETWO-56962: CLONE - [GitHub] State/Province field doesn't show as required on the add new address page. #5279
2 parents 001ddca + f558602 commit d1125a1

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ define([
2525
isMultipleCountriesAllowed: true
2626
},
2727

28+
/**
29+
*
30+
* @private
31+
*/
2832
_create: function () {
2933
this._initCountryElement();
3034

@@ -43,12 +47,18 @@ define([
4347
}, this));
4448
},
4549

46-
_initCountryElement: function() {
50+
/**
51+
*
52+
* @private
53+
*/
54+
_initCountryElement: function () {
55+
4756
if (this.options.isMultipleCountriesAllowed) {
4857
this.element.parents('div.field').show();
4958
this.element.on('change', $.proxy(function (e) {
5059
this._updateRegion($(e.target).val());
5160
}, this));
61+
5262
if (this.options.isCountryRequired) {
5363
this.element.addClass('required-entry');
5464
this.element.parents('div.field').addClass('required');
@@ -60,6 +70,7 @@ define([
6070

6171
/**
6272
* Remove options from dropdown list
73+
*
6374
* @param {Object} selectElement - jQuery object for dropdown list
6475
* @private
6576
*/
@@ -113,7 +124,7 @@ define([
113124
* @private
114125
*/
115126
_clearError: function () {
116-
if (this.options.clearError && typeof (this.options.clearError) === 'function') {
127+
if (this.options.clearError && typeof this.options.clearError === 'function') {
117128
this.options.clearError.call(this);
118129
} else {
119130
if (!this.options.form) {
@@ -122,12 +133,19 @@ define([
122133

123134
this.options.form = $(this.options.form);
124135

125-
this.options.form && this.options.form.data('validation') && this.options.form.validation('clearError',
136+
this.options.form && this.options.form.data('validator') && this.options.form.validation('clearError',
126137
this.options.regionListId, this.options.regionInputId, this.options.postcodeId);
138+
139+
// Clean up errors on region & zip fix
140+
$(this.options.regionInputId).removeClass('mage-error').parent().find('[generated]').remove();
141+
$(this.options.regionListId).removeClass('mage-error').parent().find('[generated]').remove();
142+
$(this.options.postcodeId).removeClass('mage-error').parent().find('[generated]').remove();
127143
}
128144
},
145+
129146
/**
130147
* Update dropdown list based on the country selected
148+
*
131149
* @param {String} country - 2 uppercase letter for country code
132150
* @private
133151
*/
@@ -182,11 +200,12 @@ define([
182200
if (!this.options.optionalRegionAllowed) {
183201
regionInput.attr('disabled', 'disabled');
184202
}
203+
requiredLabel.removeClass('required');
204+
regionInput.removeClass('required-entry');
185205
}
186206

187207
regionList.removeClass('required-entry').hide();
188208
regionInput.show();
189-
requiredLabel.removeClass('required');
190209
label.attr('for', regionInput.attr('id'));
191210
}
192211

@@ -208,10 +227,11 @@ define([
208227
* @private
209228
*/
210229
_checkRegionRequired: function (country) {
211-
this.options.isRegionRequired = false;
212230
var self = this;
231+
232+
this.options.isRegionRequired = false;
213233
$.each(this.options.regionJson.config.regions_required, function (index, elem) {
214-
if (elem == country) {
234+
if (elem === country) {
215235
self.options.isRegionRequired = true;
216236
}
217237
});

0 commit comments

Comments
 (0)