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
16.23k stars 2.58k forks source link

hiddenOn() and disabledOn() not working #12350

Closed NgYueHong closed 3 months ago

NgYueHong commented 3 months ago

Package

filament/filament

Package Version

3.2

Laravel Version

11

Livewire Version

No response

PHP Version

8.3

Problem description

The form input does not hide or disabled on edit.

The hide and disabled function does work when click on the edit button on the table. image

However, it does not work when click on the "edit" button from the modal. image

public static function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('name')->required(),
                TextInput::make('email')->email()->required()->disabledOn('edit'),
                TextInput::make('password')->password()->required()->hiddenOn('edit'),
            ]);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('id'),
                TextColumn::make('name'),
                TextColumn::make('email'),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\ViewAction::make()
                    ->extraModalFooterActions([
                        Tables\Actions\EditAction::make()
                    ]),
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

Expected behavior

The form should hide and disabled as well even if click from the modal button.

Steps to reproduce

Try to access the edit page from modal and you will see the disabledOn() and hiddenOn() not working.

Reproduction repository

https://github.com/NgYueHong/FilamentBug

Relevant log output

No response

dmitry-udod commented 3 months ago

@NgYueHong @zepfietje Hi all! It's not a bug.

There are two different operations edit (when you click on Edit from the list) and view.edit (when you click on Edit button from View page).

So you need to change your code from:


 TextInput::make('email')->email()->required()->disabledOn('edit'),
 TextInput::make('password')->password()->required()->hiddenOn('edit'),

To

 TextInput::make('email')->email()->required()->disabledOn(['edit', 'view.edit']),
 TextInput::make('password')->password()->required()->hiddenOn(['edit', 'view.edit']),

Here is a quick demo

https://github.com/filamentphp/filament/assets/4639175/b54e20e5-8e80-460f-9964-0b4d9934d663