filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
17.6k stars 2.75k forks source link

Masked TextInput does not update displayed value in relation edit modal #1289

Closed henninghorn closed 2 years ago

henninghorn commented 2 years ago

Package

filament/filament

Package Version

v2.9.7

Laravel Version

v8.80.0

Livewire Version

No response

PHP Version

PHP 8.1

Bug description

I have the following form on a relation manager:

public static function form(Form $form): Form
{
    return $form
        ->schema([
            TextInput::make('name'),
            Textarea::make('description'),
            TextInput::make('price')
                ->postfix('kr.')
                ->mask(fn (TextInput\Mask $mask) => $mask
                ->patternBlocks([
                    'money' => fn (Mask $mask) => $mask
                        ->numeric()
                        ->integer()
                        ->thousandsSeparator('.')
                ])
                ->pattern('money')),
        ]);
}

When I click edit on the first item, I get this modal:

billede

Whether I update the price field or not, that value it has when the modal is closed, is "transferred"/"persisted" to the next edit modal.

billede

The actual price should be 3000 (which is the value stored in the database), and not 1234, as the other package was updated to. However, if I click save, the price is not updated to the price that is displayed. So the problem seems to be front end related.

Steps to reproduce

Step 1 - Create a relation manager for a resource

Step 2 - Create a masked TextInput field for the related resource

TextInput::make('price')
    ->mask(fn (TextInput\Mask $mask) => $mask
    ->patternBlocks([
        'money' => fn (Mask $mask) => $mask
            ->numeric()
            ->integer()
            ->thousandsSeparator('.')
    ])
    ->pattern('money')),

Step 3 - Create two or more related resource, so a list of 2+ resources is displayed

Step 4 - Click edit on the first resource, then close modal and click edit on the second

The masked value from the first modal is "persisted" between any of the other edit modals until full page refresh.

Relevant log output

No response

danharrin commented 2 years ago

Any ideas how we can reload the mask reliably when the value changes @ryangjchandler? Or is this just a limitation with iMask?

danharrin commented 2 years ago

Unfortunately I think this is a limitation with iMask - it does not support changing the value after the input is loaded.

However - I'm looking into creating a MoneyInput which uses a different library and is more stable 👍

danharrin commented 2 years ago

Fixed by #1533.

intrepidws commented 2 years ago

I just tested and can confirm that PR #1533 did not fix this issue.

danharrin commented 2 years ago

Ah, thats a real shame. I assumed it did, since it does fix setting the value to null - which is where I thought this was going wrong (when switching records) 😔