Skip to content

Instantly share code, notes, and snippets.

@navarr
Created June 22, 2020 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save navarr/0bd8377996c65a1a7ad72b4d8962956a to your computer and use it in GitHub Desktop.
Save navarr/0bd8377996c65a1a7ad72b4d8962956a to your computer and use it in GitHub Desktop.
From 960e6242ce7c0090e72cc1d70a858a84198a5158 Mon Sep 17 00:00:00 2001
From: Navarr Barnier <navarr@mediotype.com>
Date: Tue, 2 Jun 2020 11:17:14 -0400
Subject: [PATCH] BUNDLE-2583
---
.../web/js/view/validation-message.js | 32 +++++++++++++++----
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/vendor/vertex/module-address-validation/view/frontend/web/js/view/validation-message.js b/vendor/vertex/module-address-validation/view/frontend/web/js/view/validation-message.js
index 67006b23..2aa4f3c2 100644
--- a/vendor/vertex/module-address-validation/view/frontend/web/js/view/validation-message.js
+++ b/vendor/vertex/module-address-validation/view/frontend/web/js/view/validation-message.js
@@ -23,7 +23,7 @@ define([
*/
initObservable: function () {
this.hasMessage = ko.pureComputed(function() {
- return Object.entries(this.message).length !== 0;
+ return this._objectHasEntries(this.message);
}.bind(this));
return this._super();
@@ -72,11 +72,9 @@ define([
* @returns {Boolean}
*/
hasMessage: function () {
- var message = this.message;
-
return ko.computed(function () {
- return Object.entries(message).length !== 0
- });
+ return this._objectHasEntries(this.message);
+ }.bind(this));
},
/**
@@ -86,6 +84,28 @@ define([
*/
clear: function () {
this.message = {};
- }
+ },
+
+ /**
+ * Return whether or not the object has any entries
+ *
+ * Object.entries is not supported by IE11 or Opera Mini.
+ * Writing a quick method to serve the same purpose was easier than
+ * importing a shim.
+ *
+ * @param {Object} object
+ * @returns {boolean}
+ * @private
+ */
+ _objectHasEntries: function(object) {
+ if (typeof Object.entries !== 'undefined') {
+ return Object.entries(object).length !== 0;
+ }
+ for (let key in object) {
+ if (object.hasOwnProperty(key)) {
+ return true;
+ }
+ }
+ },
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment