From 56804b23dfddeff244e162b71e08fffdd4b0d927 Mon Sep 17 00:00:00 2001 From: "Partica, Cristian" Date: Fri, 1 Jul 2016 15:33:19 -0500 Subject: [PATCH 1/2] MAGETWO-54785: [GitHub] State/Province field doesn't show as required on the add new address page. #5279 - fixing logic for mandatory labels and error cleanup when switching countries and updating region --- .../Checkout/view/frontend/web/js/region-updater.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js b/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js index c51fa8fa16bfb..92c8b08bee6aa 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js @@ -122,8 +122,13 @@ 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(); } }, /** @@ -182,11 +187,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')); } From addb46f7c0237c9b73c2e46740b177af6e64c577 Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Tue, 23 Aug 2016 17:11:45 -0500 Subject: [PATCH 2/2] MAGETWO-54785: [GitHub] State/Province field doesn't show as required on the add new address page - fixing eslint and jscs errors --- .../view/frontend/web/js/region-updater.js | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js b/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js index 92c8b08bee6aa..e06b8922b2252 100644 --- a/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js +++ b/app/code/Magento/Checkout/view/frontend/web/js/region-updater.js @@ -25,6 +25,10 @@ define([ isMultipleCountriesAllowed: true }, + /** + * + * @private + */ _create: function () { this._initCountryElement(); @@ -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'); @@ -60,6 +70,7 @@ define([ /** * Remove options from dropdown list + * * @param {Object} selectElement - jQuery object for dropdown list * @private */ @@ -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) { @@ -131,8 +142,10 @@ define([ $(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 */ @@ -188,7 +201,7 @@ define([ regionInput.attr('disabled', 'disabled'); } requiredLabel.removeClass('required'); - regionInput.removeClass('required-entry') + regionInput.removeClass('required-entry'); } regionList.removeClass('required-entry').hide(); @@ -214,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; } });