Jay
Jay
FFilament
Created by Jay on 3/12/2024 in #❓┊help
afterStateUpdated function not working
return $form ->schema([ Select::make('faculty_id') ->relationship('faculty', 'name') ->required(), SelectCourse::show(), Select::make('type') ->afterStateUpdated(function (Set $set, $state) { if ($state === 'Lab') { $set('performance_score', 5); // Automatically set score to 5 for 'Lab' } }) ->live() ->required() ->options([ 'Tutorial' => 'Tutorial', 'Lecture' => 'Lecture', 'Lab' => 'Lab', ]), TextInput::make('year') ->required() ->length(4) ->numeric(), Select::make('semester') ->required() ->options([ 'Semester 1' => 'Semester 1', 'Semester 2' => 'Semester 2', ]), TextInput::make('performance_score') ->dehydrated(fn (string $operation, Get $get) => $get('type') !== 'Lab') ->disabled(fn (Get $get) => $get('type') === 'Lab') ->required() ->minValue(1) ->maxValue(5) ->numeric(), ]); I need it such that performance_score will become 5, when 'Lab' is selected for type. It does correctly disable performance_score and shows 5 when I edit an existing record, but the old value is saved to the database. Also when I create a new record and choose 'Lab', there is an error - null value in column "performance_score"
2 replies
FFilament
Created by Jay on 9/26/2023 in #❓┊help
Custom registration
Hi guys, I created a custom register page as per the documentation here https://filamentphp.com/docs/3.x/panels/users#customizing-the-authentication-features Here's the code: <?php namespace App\Filament\Pages\Auth; use Filament\Forms\Components\TextInput; use Filament\Forms\Form; use Filament\Pages\Auth\Register as BaseRegister; class Register extends BaseRegister { public function form(Form $form): Form { return $form ->schema([ $this->getNameFormComponent(), $this->getEmailFormComponent(), TextInput::make('faculty_code') ->required() ->maxLength(255), $this->getPasswordFormComponent(), $this->getPasswordConfirmationFormComponent(), ]); } } Question is, how do I run validations on the faculty code field? It should be a valid code (that exists in the faculties table). Would appreciate if someone can point me in the right direction. Thank you!
4 replies
FFilament
Created by Jay on 9/26/2023 in #❓┊help
How do I check the current route the user is on?
This used to work previously, but stopped after I ran composer update. if (request()->route()->getName() == 'filament.admin.resources.courses.view') { return [ RelationManagers\PreferencesRelationManager::class, ]; } else { return []; } It says "Call to a member function getName() on null"
5 replies
FFilament
Created by Jay on 9/5/2023 in #❓┊help
Disable "Save changes" button
Is there a way to disable the "Save changes" button in the edit page? Based on certain conditions set by me.
5 replies
FFilament
Created by Jay on 9/2/2023 in #❓┊help
Repeater behaves weirdly when there are multiple of them in the same form
See attached video, where I added some items to my repeaters and am unable to remove them. Deleting an item using the button causes another item to appear in another repeater. My form consists of 3 sections, each containing a repeater. Here is the example code of the first section Section::make('Lectures') ->description('Please rank the items in order of preference, with the topmost item being your most preferred choice.') ->schema([ Repeater::make('lecture_preferences') ->label('') ->addActionLabel('Add new') ->reorderableWithButtons() ->schema([ selectCourse(), Checkbox::make('lock') ->inline(false), Checkbox::make('disable') ->inline(false), ]) ->columns(3) ->defaultItems(0), ]),
1 replies
FFilament
Created by Jay on 8/16/2023 in #❓┊help
Configuring canAccessPanel
I am using filament 3 and the new multi panel feature. I have 2 panels, one for admin and another for user. In the User.php model, i have the following: public function canAccessPanel(Panel $panel): bool { return $this->is_admin; } This works - admins can view both the admin panel and user panel. However, a normal user cannot access the user panel due to this. How do I fix this?
21 replies