woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-collection
Manish Menaria a7a1264fec
Fix input clearing issue in PriceTextField with improved currency parsing (#47354)
* Fix input clearing issue in PriceTextField with improved currency parsing

This commit addresses a usability issue in the PriceTextField component, highlighted by @dinhtungdu, where the input field would clear itself if users omitted a space between the numeric value and the currency symbol when the currency is configured to appear on the right with a space (e.g., "20$" instead of "20 $"). The problem was rooted in the strict parsing logic that did not account for variations in user input related to currency formatting.

The fix involves an enhancement to the numeric parsing function, which now effectively handles various user inputs regardless of space or placement of the currency symbol. The revised parsing logic uses a regular expression to strip out any characters that are not numeric or the designated decimal separator, and then replaces the locale-specific decimal separator with a period for standard numeric conversion. This approach not only fixes the specific issue but also improves the robustness of the component against similar input variations.

* Refactor currency parsing and improve handling in PriceTextField

1. Renaming `formatValueAsCurrency` to `formatNumberAsCurrency` to better
   reflect its functionality.
2. Moving the `convertCurrencyStringToNumber` function outside of the
   PriceTextField component, enhancing readability and reusability.
3. Changing the internal state handling from `newValue` to `inputValue`,
   directly managing the string input and parsing it as needed for further
   processing. This will force input field to re-render.

* Add changefile(s) from automation for the following project(s): woocommerce-blocks

* Fix: Handle empty string in price conversion to prevent 0 value

This commit fixes an issue where an empty string in the price conversion function resulted in a value of 0. Now, empty strings are properly handled and do not convert to a numerical value.

---------

Co-authored-by: github-actions <github-actions@github.com>
2024-05-16 13:23:47 +05:30
..
collections Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30
edit Fix input clearing issue in PriceTextField with improved currency parsing (#47354) 2024-05-16 13:23:47 +05:30
inner-blocks/no-results New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
variations Restructure Product Collection editor files (https://github.com/woocommerce/woocommerce-blocks/pull/11981) 2023-12-06 15:50:24 +01:00
block.json Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30
constants.ts Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30
frontend.tsx Product Collection: Disable client side navigation if blocks incompatible with Interactivity API are detected (#45435) 2024-03-18 08:24:03 +01:00
icon.tsx Foundation of New Product Collection Block (https://github.com/woocommerce/woocommerce-blocks/pull/9352) 2023-05-15 08:51:49 +00:00
index.tsx Fix: Enable Pagination Block Visibility in Product Collection Block (#43132) 2023-12-29 15:45:29 +05:30
save.tsx Foundation of New Product Collection Block (https://github.com/woocommerce/woocommerce-blocks/pull/9352) 2023-05-15 08:51:49 +00:00
style.scss Improve Accessibility in Product Collection Navigation (#44599) 2024-02-19 11:35:14 +05:30
tracks-utils.ts Fix: handle undefined templateSlug in Product Collection tracking utils (#47504) 2024-05-16 11:17:52 +05:30
types.ts Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30
utils.tsx Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30