Quantity widget doesn't work correct with large numbers

Created on 23 April 2024, 2 months ago
Updated 8 May 2024, about 2 months ago

When value greater than 999 is used in quantity widget, it's saved in db, but is not displayed when editing the value again.

To reproduce the bug, edit order and quantity of the order's item. Use value 1000 or any other greater than 999 number. Save the item. Try to edit it again. You should get empty quantity field, but when you will inspect source code of the input element you will find number with comma(s) in 'value' attribute.

For example 1000 will be saved in db as 1000.00.

<input data-drupal-selector="edit-quantity-0-value" type="number" id="edit-quantity-0-value" name="quantity[0][value]" value="1,000" step="1" min="1" placeholder="" class="form-number required form-element form-element--type-number form-element--api-number" required="required" aria-required="true">

The same bug can be re-produced when editing price list item (when using commerce_pricelist module).

I've found that it can be fixed by replacing:
$element['value']['#default_value'] = number_format($element['value']['#default_value'], $decimal_places);
with
$element['value']['#default_value'] = number_format($element['value']['#default_value'], $decimal_places, '.', '');
in the QuantityWidget class.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Other

Created by

🇺🇦Ukraine khiminrm

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024