F
Filament16mo ago
fadil

How to connect input form

I want to make the following form inputs connected to each other the following inputs: TextInput::make('booking_duration') ->label('Durasi Booking (satuan jam') ->required() ->numeric(), and after this input is filled as well: TimePicker::make('start_time') ->label('Waktu Mulai') ->required(), and then this input will automatic filled: TimePicker::make('end_time') ->label('Waktu Selesai') ->required() ->reactive(), so the input end_time will be filled if start_time was prefilled with the start_time being advanced according to its duration can you explain?
9 Replies
Tin
Tin16mo ago
You can use $get and $set closures
Tin
Tin16mo ago
Tin
Tin16mo ago
And afterStateUpdated() input method Write afterStateUpdated(function ($state, $set) on your start_time input. Then, in you closure use $set('end_time',$state)
fadil
fadilOP16mo ago
but how to make the end time the result of the start time added with the duration of other inputs?
Tin
Tin16mo ago
If you add afterStateUpdated to your start_time input, you will have the $state variable resolved that will hold your input value. And then use $get('booking_duration')
Vp
Vp16mo ago
fadil
fadilOP16mo ago
like this? ->reactive() ->afterStateUpdated(function (Closure $set, $state) { fn (Get $get): bool => !$get('booking_duration'); $set('end_time', Str::end_time($state)); }) i dont know the structure?
Vp
Vp16mo ago
When duration is enter, what will be the start_time.?
Tin
Tin16mo ago
No, $get should be listed with the parameters as $set and $state then you can use it in your closure
Want results from more Discord servers?
Add your server