Skip to content

Commit

Permalink
Avoid JS errors if the zipcode field has no label (OpenMage#3197)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabrizio Balliano <fabrizio.balliano@gmail.com>
Co-authored-by: Ng Kiat Siong <kiatsiong.ng@gmail.com>
  • Loading branch information
3 people authored Apr 24, 2023
1 parent a6c6753 commit cde7af5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions js/varien/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,13 @@ ZipUpdater.prototype = {

_setPostcodeOptional: function(){
this.zipElement = $(this.zipElement);
if (this.zipElement == undefined) {
if (this.zipElement === undefined) {
return false;
}

// find label
var label = $$('label[for="' + this.zipElement.id + '"]')[0];
if (label != undefined) {
if (label !== undefined) {
var wildCard = label.down('em') || label.down('span.required');
if (!wildCard) {
label.insert(' <span class="required">*</span>');
Expand All @@ -400,21 +400,21 @@ ZipUpdater.prototype = {

// Make Zip and its label required/optional
if (optionalZipCountries.indexOf(this.country) != -1) {
if (label.hasClassName('required')) {
if (label !== undefined && label.hasClassName('required')) {
label.removeClassName('required');
}
while (this.zipElement.hasClassName('required-entry')) {
this.zipElement.removeClassName('required-entry');
}
if (wildCard != undefined) {
if (wildCard !== undefined) {
wildCard.hide();
}
} else {
if (!label.hasClassName('required')) {
if (label !== undefined && !label.hasClassName('required')) {
label.addClassName('required');
}
this.zipElement.addClassName('required-entry');
if (wildCard != undefined) {
if (wildCard !== undefined) {
wildCard.show();
}
}
Expand Down

0 comments on commit cde7af5

Please sign in to comment.