In Laravel Filament(V3) how to update the value of a TextInput field dynamically on changing of Select input field

43 views Asked by At

In my BatchResource class I have created a form to select a course and populate the course_fee for the selected course. Below is the code:

public static function form(Form $form): Form
{
    return $form
        ->schema([
            Select::make('course_id')->placeholder('Select a course')->required()->native(false)
                ->relationship(name: 'course', titleAttribute: 'name')
                ->live()
                ->columnSpan(2) ,
            TextInput::make('course_fee')->numeric()->required()->columnSpan(2),
        ])
        ->columns(3);
}

Now I want display course_fee (from Course model) in the TextInput field based on the course selected.

I am able to achieved it using afterStateUpdated() as:

    ->live()
    ->afterStateUpdated(fn (Set $set, Get $get) => $set('course_fee', Course::find($get('course_id'))->course_fee))

However, here I am querying using Course model again. As the same Course model was already invoked while selecting the course using Select input field, is there any way to access the already selected model instead of manually querying again?

Filament Version: 3.2 Laravel Version: 10

0

There are 0 answers