Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x]: Unable to Input Negative Values in Money Field and Inconsistent Minimum/Maximum Value Display #15565

Closed
mersy opened this issue Aug 20, 2024 · 2 comments
Assignees
Labels

Comments

@mersy
Copy link

mersy commented Aug 20, 2024

What happened?

Description

There appears to be an issue with the money field where entering negative values results in the field displaying as empty. Despite being able to save -999 as the minimum value for the field, entering and saving a negative value like -999 in an entry causes the value to disappear.
Additionally, there seems to be a discrepancy in the display of minimum and maximum values when set to -999 and 999, which appear as -99,000 and 99,900, respectively. This might be related to currency formatting, particularly with Japanese Yen, but it could be affecting other currencies as well.

The documentation wasn't clear on whether negative values can be entered. However, since the following query was mentioned, I assumed that negative values might be allowed.

['or', '< -100.00', '> 100.00']

https://craftcms.com/docs/5.x/reference/field-types/money.html#querying-elements-with-money-fields

Steps to reproduce

  1. Modify Field Settings:
    1. Navigate to the settings of the money field in question.
    2. Remove the default minimum value of 0 and set the minimum value to -999.
    3. Save the settings.
  2. Attempt to Input Negative Value:
    1. Go to an entry that uses the modified money field.
    2. Try to input a value of -99 and save the entry.
    3. Observe that the field appears empty instead of displaying the entered value.

===

  1. Check Display of Minimum/Maximum Values:
    1. Set the minimum and maximum values of the field to -999 and 999, respectively.
    2. Observe the displayed values; instead of showing -999 and 999, the field displays -99,000 and 99,900.
    3. Note that this issue might be related to currency formatting, particularly with Japanese Yen.

Expected behavior

  1. Modify Field Settings:
    1. After removing the default minimum value of 0 and setting the minimum value to -999, the field should accept and display negative values without issue.
  2. Attempt to Input Negative Value:
    1. When a negative value like -99 is entered into the field and the entry is saved, the field should correctly display the entered negative value instead of appearing empty.

I would first like to know if negative values can be used in the money field.

===

  1. Check Display of Minimum/Maximum Values:
    1. When the minimum and maximum values of the field are set to -999 and 999, they should be displayed as -999 and 999 respectively, without unexpected changes (e.g., -99,000 and 99,900). The field should accurately reflect the specified values according to the selected currency formatting, including for Japanese Yen.

Actual behavior

  1. Attempt to Input Negative Value:
    1. When a negative value like -99 is entered into the field and the entry is saved, the field appears empty instead of displaying the entered value.

set value
20240820-150525

after save
20240820-150532

===

  1. Check Display of Minimum/Maximum Values:
    1. When the minimum and maximum values of the field are set to -999 and 999, they are unexpectedly displayed as -99,000 and 99,900, respectively. This discrepancy seems to be influenced by the currency formatting, particularly for Japanese Yen, leading to incorrect value displays.

set value
20240820-143823

after save
20240820-143830

Craft CMS version

5.3.4

PHP version

8.2.22

Operating system and version

Linux 3.10.0-957.27.2.el7.x86_64

Database type and version

MySQL 8.0.35

Image driver and version

Imagick 3.7.0 (ImageMagick 6.7.8-9)

Installed plugins and versions

  • CKEditor 4.1.0
  • Multi Translator 2.7.0
@i-just
Copy link
Contributor

i-just commented Aug 20, 2024

Hi, thanks for reporting and for the detailed description!

Yes, negative values are allowed in the money field. It looks like there’s a bug (only affecting version 5.2.9+) which prevents them from showing correctly after they’re saved in the database.

Display of Minimum/Maximum values with the Japanese Yen currency - that’s also a bug. I raised a PR for that one, too.

@brandonkelly
Copy link
Member

Craft 4.11.4 and 5.3.5 are out with those fixes. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants