F
Filament9mo ago
Jay

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"
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server