From 0aa022ffeadbb0475292259be80c68231061d920 Mon Sep 17 00:00:00 2001 From: Touza El Hassan <131183815+elhassantouza@users.noreply.github.com> Date: Thu, 9 May 2024 16:00:59 +0100 Subject: [PATCH] SHOP-1497 : Display error message when total cart amount is greater than max checkout amount (#177) ## JIRA Ticket [SHOP-1497](https://youcanshop.atlassian.net/browse/SHOP-1497) ## QA Steps - [ ] `pnpm i` - [ ] `pnpm dev` ## Note Leave empty when you have nothing to say [SHOP-1497]: https://youcanshop.atlassian.net/browse/SHOP-1497?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --- assets/main.js | 19 +++++++++++++++++++ layouts/theme.liquid | 6 ++++++ 2 files changed, 25 insertions(+) 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 }}