pelmered / filament-money-field

Money field powered by Money PHP
MIT License
40 stars 19 forks source link

Money field disappear after 'afterStateUpdated' another select field #10

Closed dmazlum closed 5 months ago

dmazlum commented 5 months ago

Hello Money field disappears after the select field is selected. It returns the normal text field. Would you happen to have any advice?

`Select::make('bank_id') ->required() ->validationMessages([ 'required' => 'Banka alanı gereklidir.', ]) ->placeholder('Seçiniz') ->label('Banka') ->options(function () use ($user) {

                            return DbsUserBank::where('customer_id', $user->id)
                                ->with('bank')
                                ->get()
                                ->mapWithKeys(function ($bank) {
                                    return [$bank->bank_id => $bank->bank->bank_name];
                                });
                        })
                        ->live()
                        ->afterStateUpdated(function (Set $set, ?string $state) {

                            if (!is_null($state)) {
                                // Set Limit
                                $limit = self::getBankLimit();

                                $set('limit', $limit);
                            } else {
                                $set('limit', null);
                            }
                        })
                        ->native(false),

                    MoneyInput::make('amount')
                        ->required()
                        ->validationMessages([
                            'required' => 'Ödenecek Miktar alanı gereklidir.',
                        ])
                        ->label('Ödenecek Miktar')
                        ->helperText(fn(Get $get): string => $get('limit') ? 'Limit: ' . $get('limit') . ' ₺' : '')
                        ->placeholder('Ödeme yapılacak miktarı giriniz')
                        ->live(onBlur: true)
                        ->afterStateUpdated(function (Get $get, ?int $state) {

                            $limit = $get('limit');

                            if ($state > $limit && $limit !== null) {

                                Notification::make()
                                    ->icon('heroicon-o-exclamation-circle')
                                    ->iconColor('danger')
                                    ->color('danger')
                                    ->title('Ödeme Limit Uyarısı')
                                    ->body('Ödenecek miktar limitinizi aşmaktadır. Lütfen limitinizi kontrol ediniz.')
                                    ->send();
                            }
                        }),`
pelmered commented 5 months ago

Thank you for the report. I will investigate this.

pelmered commented 5 months ago

I have made some refactoring on how this works. Can you see if this works better in 1.2.0-beta?

pelmered commented 5 months ago

@dmazlum I think this should be fixed in the latest release (1.2.0). Can you verify?

dmazlum commented 5 months ago

@pelmered Hello again. The bug is fixed 1.2 version. I tried and did not see any error. Thanx alot.

pelmered commented 5 months ago

Ok, great! Thank you for confirming.