@@ -25,6 +25,10 @@ define([
25
25
isMultipleCountriesAllowed : true
26
26
} ,
27
27
28
+ /**
29
+ *
30
+ * @private
31
+ */
28
32
_create : function ( ) {
29
33
this . _initCountryElement ( ) ;
30
34
@@ -43,12 +47,18 @@ define([
43
47
} , this ) ) ;
44
48
} ,
45
49
46
- _initCountryElement : function ( ) {
50
+ /**
51
+ *
52
+ * @private
53
+ */
54
+ _initCountryElement : function ( ) {
55
+
47
56
if ( this . options . isMultipleCountriesAllowed ) {
48
57
this . element . parents ( 'div.field' ) . show ( ) ;
49
58
this . element . on ( 'change' , $ . proxy ( function ( e ) {
50
59
this . _updateRegion ( $ ( e . target ) . val ( ) ) ;
51
60
} , this ) ) ;
61
+
52
62
if ( this . options . isCountryRequired ) {
53
63
this . element . addClass ( 'required-entry' ) ;
54
64
this . element . parents ( 'div.field' ) . addClass ( 'required' ) ;
@@ -60,6 +70,7 @@ define([
60
70
61
71
/**
62
72
* Remove options from dropdown list
73
+ *
63
74
* @param {Object } selectElement - jQuery object for dropdown list
64
75
* @private
65
76
*/
@@ -113,7 +124,7 @@ define([
113
124
* @private
114
125
*/
115
126
_clearError : function ( ) {
116
- if ( this . options . clearError && typeof ( this . options . clearError ) === 'function' ) {
127
+ if ( this . options . clearError && typeof this . options . clearError === 'function' ) {
117
128
this . options . clearError . call ( this ) ;
118
129
} else {
119
130
if ( ! this . options . form ) {
@@ -122,12 +133,19 @@ define([
122
133
123
134
this . options . form = $ ( this . options . form ) ;
124
135
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' ,
126
137
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 ( ) ;
127
143
}
128
144
} ,
145
+
129
146
/**
130
147
* Update dropdown list based on the country selected
148
+ *
131
149
* @param {String } country - 2 uppercase letter for country code
132
150
* @private
133
151
*/
@@ -182,11 +200,12 @@ define([
182
200
if ( ! this . options . optionalRegionAllowed ) {
183
201
regionInput . attr ( 'disabled' , 'disabled' ) ;
184
202
}
203
+ requiredLabel . removeClass ( 'required' ) ;
204
+ regionInput . removeClass ( 'required-entry' ) ;
185
205
}
186
206
187
207
regionList . removeClass ( 'required-entry' ) . hide ( ) ;
188
208
regionInput . show ( ) ;
189
- requiredLabel . removeClass ( 'required' ) ;
190
209
label . attr ( 'for' , regionInput . attr ( 'id' ) ) ;
191
210
}
192
211
@@ -208,10 +227,11 @@ define([
208
227
* @private
209
228
*/
210
229
_checkRegionRequired : function ( country ) {
211
- this . options . isRegionRequired = false ;
212
230
var self = this ;
231
+
232
+ this . options . isRegionRequired = false ;
213
233
$ . each ( this . options . regionJson . config . regions_required , function ( index , elem ) {
214
- if ( elem == country ) {
234
+ if ( elem === country ) {
215
235
self . options . isRegionRequired = true ;
216
236
}
217
237
} ) ;
0 commit comments