From 84f7368bc9343f2107345715b883e9f9fe264627 Mon Sep 17 00:00:00 2001 From: "Krzysztof Gacek (Harvel)" <59796176+Harvel218@users.noreply.github.com> Date: Wed, 30 Mar 2022 15:18:47 +0200 Subject: [PATCH] Frontend/update - button validation + error prevent (#13) * addition of optional next btn validaiton * prevent rendering errors regarding wrong backend output or api changes * hotfix * cr feedback apply --- .../assets/common/js/geowidget/GeoWidgetPreview.js | 4 ++++ src/Resources/assets/shop/js/inpostPointEvents.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Resources/assets/common/js/geowidget/GeoWidgetPreview.js b/src/Resources/assets/common/js/geowidget/GeoWidgetPreview.js index d6da433..e474ff0 100644 --- a/src/Resources/assets/common/js/geowidget/GeoWidgetPreview.js +++ b/src/Resources/assets/common/js/geowidget/GeoWidgetPreview.js @@ -27,6 +27,10 @@ export class GeoWidgetPreview { throw new Error('BitBagInPostPlugin - The specified wrapper node could not be found in the DOM'); } + if (!data) { + return; + } + this.wrapper.innerHTML = ''; this.wrapper.insertAdjacentHTML( 'beforeend', diff --git a/src/Resources/assets/shop/js/inpostPointEvents.js b/src/Resources/assets/shop/js/inpostPointEvents.js index c4c8755..8097902 100644 --- a/src/Resources/assets/shop/js/inpostPointEvents.js +++ b/src/Resources/assets/shop/js/inpostPointEvents.js @@ -2,9 +2,16 @@ import triggerCustomEvent from '../../common/js/utilities/triggerCustomEvent'; import {ValidateNextBtn} from './nextBtnValidation'; export class InpostPointEvents { - constructor() { + constructor(config = {}) { const inputs = [...document.querySelectorAll('[value="inpost_point"]')]; this.shippingGroups = inputs.map((input) => [...document.querySelectorAll(`[name="${input.name}"]`)]); + this.defaultConfig = { + validateNextBtn: true, + }; + this.finalConfig = { + ...this.defaultConfig, + ...config, + }; } init() { @@ -24,6 +31,11 @@ export class InpostPointEvents { `inpost.point.${field.value === 'inpost_point' ? 'selected' : 'deselected'}` ); }); + + if (!validateNextBtn) { + return; + } + new ValidateNextBtn({node: field}).init(); }); });