From b822cbe0116cb589c064ca7ebf8b07b1696e6cf8 Mon Sep 17 00:00:00 2001 From: "Theo VINCENT (thvi)" Date: Tue, 8 Aug 2023 13:00:19 +0000 Subject: [PATCH] [FIX] point_of_sale: invalid money input display Since the use of Bootstrap, the money inputs using the useValidateCashInput hook are no longer correctly displayed when the user input is invalid. Steps to reproduce: - Open a session in a shop - Open the "Cash In/Out" menu with the top right dropdown menu - Enter an invalid amount, like "invalid" for example The input is not displayed with red borders. This commit fixes the display of invalid inputs in the Cash In/Out and Closing Session popups, using the Bootstrap is-invalid CSS class. closes odoo/odoo#131246 Task-id: 3444048 Signed-off-by: Vlad Stroia (vlst) --- addons/point_of_sale/static/src/app/utils/hooks.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/point_of_sale/static/src/app/utils/hooks.js b/addons/point_of_sale/static/src/app/utils/hooks.js index 8cf09c79cdd..71e1f1cf85a 100644 --- a/addons/point_of_sale/static/src/app/utils/hooks.js +++ b/addons/point_of_sale/static/src/app/utils/hooks.js @@ -101,18 +101,21 @@ export function useValidateCashInput(inputRef, startingValue) { const decimalPoint = localization.decimalPoint; const env = useEnv(); function handleCashInputChange(event) { - let inputValue = (event.target.value || "").trim(); + const inputValue = (event.target.value || "").trim(); // Check if the current input value is a valid float + const inputElement = event.target.closest(".input-container") || event.target; if (!env.utils.isValidFloat(inputValue)) { - event.target.classList.add('invalid-cash-input'); + inputElement.classList.add("is-invalid"); + event.target.classList.add("invalid-cash-input"); } else { - event.target.classList.remove('invalid-cash-input'); + inputElement.classList.remove("is-invalid"); + event.target.classList.remove("invalid-cash-input"); } } onMounted(() => { if (cashInput.el) { - cashInput.el.value = (startingValue || 0).toString().replace('.', decimalPoint); + cashInput.el.value = (startingValue || 0).toString().replace(".", decimalPoint); cashInput.el.addEventListener("input", handleCashInputChange); } }); @@ -120,5 +123,5 @@ export function useValidateCashInput(inputRef, startingValue) { if (cashInput.el) { cashInput.el.removeEventListener("input", handleCashInputChange); } - }) + }); }