Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Dependent currency field not storing value as minor units #6695

Closed
gerardnll opened this issue Jan 29, 2025 · 2 comments
Closed

Dependent currency field not storing value as minor units #6695

gerardnll opened this issue Jan 29, 2025 · 2 comments
Labels
pending Issues that are pending triage

Comments

@gerardnll
Copy link

gerardnll commented Jan 29, 2025

  • Laravel Version: 11.41.0
  • Nova Version: 5.1.8
  • PHP Version: 8.4.3
  • Database Driver & Version:
  • Operating System and Version: #.#
  • Browser type and version: #.#
  • Reproduction Repository: https://github.com/###/###

Description:

When toggling visibility of two fields and one of them is a currency field even though I have specified that the currency is in minor units it's not properly storing the value correctly. When typing 2, it stores 2 instead of 200. This bug does not occur when switching the order of the dependOn fields. I think it only happens when these two dependent fields share the same column.

Detailed steps to reproduce the issue on a fresh Nova installation:

Create a resource that has 3 fields. The first one is a select with two options. After this field add Currency field that has ->asMinorUnits(). After this one add a Number field. These last two fields dependOn the value of the first one, only one of them is shown depending on the option selected on the first field.

Select::make('type')->options([
    'unit' => 'Unit',
    'percent' => 'Percent',
])->displayUsingLabels()
    ->default('unit')
    ->rules('required', 'string', 'in:unit,percent'),

// Percent
Number::make('amount')
    ->hide()
    ->min(0)
    ->default(0)
    ->step(0.01)
    ->max(100)
    ->dependsOn('type',
        function (Number $field, NovaRequest $request, FormData $formData) {
            if ($formData->type === 'percent') {
                $field->show()->rules(['required', 'numeric', 'min:0', 'max:100']);
            }
        }
    ),

// Monetary amount 
Currency::make('amount')
    ->currency('EUR')
    ->asMinorUnits()
    ->hide()
    ->dependsOn('type',
        function (Currency $field, NovaRequest $request, FormData $formData) {
            if ($formData->type === 'unit') {
                $field->show()->rules(['required', 'numeric', 'min:0']);
            }
        }
    ),
@crynobone
Copy link
Member

Can you show a screen video describing the issue.

@crynobone crynobone added the needs more info More information is required label Jan 30, 2025
@gerardnll
Copy link
Author

Yes sure. First I show you the buggy set up. You can see it stores 0,02€ (2 in DB) instead of 200 which means 2€. After switching the order of the fields it properly stores 200 which is 2€.

Gravacio.de.pantalla.2025-01-30.a.les.9.28.38.mov

@crynobone crynobone added pending Issues that are pending triage and removed needs more info More information is required labels Jan 30, 2025
@laravel laravel locked and limited conversation to collaborators Jan 31, 2025
@crynobone crynobone converted this issue into discussion #6699 Jan 31, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
pending Issues that are pending triage
Projects
None yet
Development

No branches or pull requests

2 participants