Open AlexanderBV opened 4 weeks ago
Thank you for the report! I will investigate this today.
I don't believe this error has anything to with this plugin. It is how Filament works.
I think you have to do something like this:
MoneyInput::make('price')
->label('Precio')
->afterStateUpdated(function (MoneyInput $component, bool $state) {
$component->currency(fn($get) => $get('unit_price_currency') ?? 'USD')
->locale(fn($get) => $get('unit_price_locale') ?? 'es_PE');
})
I have now tested some, and I'm not sure how well it works to change the field dynamically like this. This is something I will have to look into in the future. For now I would probably just use a currency select and a normal input without localized format. For displaying it should work with the MoneyColumn
and the MoneyEntry
.
If you find a way to support this, please let me know.
Describe the bug I'm encountering an error when trying to dynamically set the currency and locale for the
MoneyInput
component in Filament forms. The error occurs specifically when trying to use a closure for thecurrency
property.Error Message Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
The error is triggered by this line:
Changes have in global config:
// .env file settings MONEY_DEFAULT_LOCALE=es_PE MONEY_DEFAULT_CURRENCY=PEN
// Configuration published with php artisan vendor:publish --provider="Pelmered\FilamentMoneyField\FilamentMoneyFieldServiceProvider" --tag="config"
Expected behavior and actual behavior I expected the MoneyInput component to correctly use the dynamically set currency and locale values without causing initialization errors. Instead, it throws an error indicating that the property $container must not be accessed before initialization.
Screenshots![Screenshot from 2024-06-26 11-31-49](https://github.com/pelmered/filament-money-field/assets/20906718/7d312658-3d56-4e39-8f01-102a86706384)
Additional context I believe the issue might be related to the initialization of the $container property, which seems to be accessed before it is fully initialized. Any insights or solutions to this problem would be greatly appreciated. Thank you for your assistance!
Version of: This package: Latest Filament: 3.2 PHP: 8.2 Laravel: 10.10