Skip to content

Commit

Permalink
Merge pull request #293 from magento-fearless-kiwis/FearlessKiwis-MAG…
Browse files Browse the repository at this point in the history
…ETWO-54785-State-province-not-required-mainline

[Fearless kiwis] MAGETWO-54785: [GitHub] State/Province field doesn't show as required on the add new address page. #5279
  • Loading branch information
heyitsroberthe committed Aug 26, 2016
2 parents 8063845 + 17da6de commit 661a3a9
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions app/code/Magento/Checkout/view/frontend/web/js/region-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ define([
isMultipleCountriesAllowed: true
},

/**
*
* @private
*/
_create: function () {
this._initCountryElement();

Expand All @@ -43,12 +47,18 @@ define([
}, this));
},

_initCountryElement: function() {
/**
*
* @private
*/
_initCountryElement: function () {

if (this.options.isMultipleCountriesAllowed) {
this.element.parents('div.field').show();
this.element.on('change', $.proxy(function (e) {
this._updateRegion($(e.target).val());
}, this));

if (this.options.isCountryRequired) {
this.element.addClass('required-entry');
this.element.parents('div.field').addClass('required');
Expand All @@ -60,6 +70,7 @@ define([

/**
* Remove options from dropdown list
*
* @param {Object} selectElement - jQuery object for dropdown list
* @private
*/
Expand Down Expand Up @@ -113,7 +124,7 @@ define([
* @private
*/
_clearError: function () {
if (this.options.clearError && typeof (this.options.clearError) === 'function') {
if (this.options.clearError && typeof this.options.clearError === 'function') {
this.options.clearError.call(this);
} else {
if (!this.options.form) {
Expand All @@ -122,12 +133,19 @@ define([

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

this.options.form && this.options.form.data('validation') && this.options.form.validation('clearError',
this.options.form && this.options.form.data('validator') && this.options.form.validation('clearError',
this.options.regionListId, this.options.regionInputId, this.options.postcodeId);

// Clean up errors on region & zip fix
$(this.options.regionInputId).removeClass('mage-error').parent().find('[generated]').remove();
$(this.options.regionListId).removeClass('mage-error').parent().find('[generated]').remove();
$(this.options.postcodeId).removeClass('mage-error').parent().find('[generated]').remove();
}
},

/**
* Update dropdown list based on the country selected
*
* @param {String} country - 2 uppercase letter for country code
* @private
*/
Expand Down Expand Up @@ -182,11 +200,12 @@ define([
if (!this.options.optionalRegionAllowed) {
regionInput.attr('disabled', 'disabled');
}
requiredLabel.removeClass('required');
regionInput.removeClass('required-entry');
}

regionList.removeClass('required-entry').hide();
regionInput.show();
requiredLabel.removeClass('required');
label.attr('for', regionInput.attr('id'));
}

Expand All @@ -208,10 +227,11 @@ define([
* @private
*/
_checkRegionRequired: function (country) {
this.options.isRegionRequired = false;
var self = this;

this.options.isRegionRequired = false;
$.each(this.options.regionJson.config.regions_required, function (index, elem) {
if (elem == country) {
if (elem === country) {
self.options.isRegionRequired = true;
}
});
Expand Down

0 comments on commit 661a3a9

Please sign in to comment.