woocommerce/plugins/woocommerce-blocks/assets/js/blocks/product-collection/edit
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
..
inspector-advanced-controls Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30
inspector-controls Fix input clearing issue in PriceTextField with improved currency parsing (#47354) 2024-05-16 13:23:47 +05:30
toolbar-controls Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30
collection-chooser.tsx New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
collection-selection-modal.tsx New flow of adding Product Collection and basic set of Collections (#42696) 2023-12-27 11:07:27 +01:00
editor.scss Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30
index.tsx Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30
product-collection-content.tsx Product Collection: Implement Preview Mode (#46369) 2024-05-15 13:18:43 +05:30
product-collection-placeholder.tsx Product Collection: telemetry choosing collection (#45827) 2024-04-02 14:12:20 +02:00