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
19.03k stars 2.94k forks source link

The value for hidden or non-visible fields is not sent to the backend #13773

Closed 8sammy8 closed 3 months ago

8sammy8 commented 3 months ago

Package

filament/forms

Package Version

v3.2.40

Laravel Version

v11.14.0

Livewire Version

No response

PHP Version

PHP 8.2

Problem description

the value for hidden or non-visible fields is not sent to the backend

Expected behavior

should send values ​​for hidden fields if its value has changed

Steps to reproduce

when enable_mb_limit is not active, data for mb limit is not sent, although when changing to inactive, the value for mb_limit is reset.

not hidden not visible does not work in this context, if you remove these fields then it's ok. ->dehydrated(true) also does not help.

Checkbox::make('enable_mb_limit')
                    ->label('Enable MB Limit')
                    ->reactive()
                    ->afterStateHydrated(function (Checkbox $component, callable $set, $get) {
                        $set('enable_mb_limit', $get('mb_limit') > self::DEFAULT_LIMIT);
                    })
                    ->afterStateUpdated(function ($state, callable $set) {
                        if (!$state) {
                            $set('mb_limit', self::DEFAULT_LIMIT);
                        }
                    })
                    ->dehydrateStateUsing(function ($state, $get) {

                    })
                    ->columnSpanFull(),
                TextInput::make('mb_limit')
                    ->label('MB Limit')
                    ->numeric()
                    ->required()
                    ->default(self::DEFAULT_LIMIT)
                    ->minValue(self::DEFAULT_LIMIT)
                    ->suffix('MB')
                    ->hidden(fn ($get) => !$get('enable_mb_limit'))
                    ->dehydrateStateUsing(function ($state, $get) {
                        if (!$get('enable_mb_limit')) {
                            return self::DEFAULT_LIMIT;
                        }
                        return $state;
                    })
                    ->columnSpanFull(),

Reproduction repository (issue will be closed if this is not valid)

https://github.com/filamentphp/filament

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

github-actions[bot] commented 3 months ago

Hey @8sammy8! We're sorry to hear that you've hit this issue. 💛

However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue?

We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly.