diff --git a/assets/main.js b/assets/main.js index 84770883..9b78a0f1 100644 --- a/assets/main.js +++ b/assets/main.js @@ -338,3 +338,22 @@ function processVideoSections() { } processVideoSections(); + +function decodeHtmlEntities(text) { + let textarea = document.createElement('textarea'); + textarea.innerHTML = text; + + return textarea.value; +} + +function renderTextContent(htmlContent) { + let tempElement = document.createElement('div'); + tempElement.innerHTML = htmlContent; + + return tempElement.innerText || tempElement.textContent; +} + +if (FORM.errors) { + let decodedText = decodeHtmlEntities(FORM.errors); + notify(renderTextContent(decodedText), 'error', 20000); +} diff --git a/layouts/theme.liquid b/layouts/theme.liquid index 419230dc..99d08259 100644 --- a/layouts/theme.liquid +++ b/layouts/theme.liquid @@ -25,6 +25,12 @@ {% section 'main-footer' %} {%- render 'cart-drawer' -%} + {% javascript %} + const FORM = { + errors: '{{ form.errors | first }}', + } + {% endjavascript %} + {{ 'main.js' | asset_url | script_tag }}