Skip to content

Commit

Permalink
Added support for making Prototype validator optional (#3053)
Browse files Browse the repository at this point in the history
  • Loading branch information
loekvangool authored and fballiano committed Mar 10, 2023
1 parent c162ba2 commit f0212b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
16 changes: 12 additions & 4 deletions js/varien/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ VarienForm.prototype = {
this.cache = $A();
this.currLoader = false;
this.currDataIndex = false;
this.validator = new Validation(this.form);
if (typeof Validation === 'function') {
this.validator = new Validation(this.form);
}
this.elementFocus = this.elementOnFocus.bindAsEventListener(this);
this.elementBlur = this.elementOnBlur.bindAsEventListener(this);
this.childLoader = this.onChangeChildLoad.bindAsEventListener(this);
Expand Down Expand Up @@ -187,7 +189,9 @@ RegionUpdater.prototype = {
var regionRequired = this.config.regions_required.indexOf(this.countryEl.value) >= 0;

elements.each(function(currentElement) {
Validation.reset(currentElement);
if (typeof Validation !== 'undefined') {
Validation.reset(currentElement);
}
label = $$('label[for="' + currentElement.id + '"]')[0];
if (label) {
wildCard = label.down('em') || label.down('span.required');
Expand Down Expand Up @@ -293,7 +297,9 @@ RegionUpdater.prototype = {
this.regionTextEl.style.display = '';
}
this.regionSelectEl.style.display = 'none';
Validation.reset(this.regionSelectEl);
if (typeof Validation !== 'undefined') {
Validation.reset(this.regionSelectEl);
}
} else if (this.disableAction == 'disable') {
if (this.regionTextEl) {
this.regionTextEl.disabled = false;
Expand Down Expand Up @@ -373,7 +379,9 @@ ZipUpdater.prototype = {

// Ajax-request and normal content load compatibility
if (this.zipElement != undefined) {
Validation.reset(this.zipElement);
if (typeof Validation !== 'undefined') {
Validation.reset(this.zipElement);
}
this._setPostcodeOptional();
} else {
Event.observe(window, "load", this._setPostcodeOptional.bind(this));
Expand Down
12 changes: 7 additions & 5 deletions js/varien/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,13 @@ Varien.FileElement.prototype = {
}
};

Validation.addAllThese([
['validate-custom', ' ', function(v,elm) {
return elm.validate();
}]
]);
if (typeof Validation !== 'undefined') {
Validation.addAllThese([
['validate-custom', ' ', function(v,elm) {
return elm.validate();
}]
]);
}

function truncateOptions() {
$$('.truncated').each(function(element){
Expand Down

0 comments on commit f0212b0

Please sign in to comment.