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
Tin2y ago
You can use $get and $set closures
Tin
Tin2y ago
Tin
Tin2y 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
fadilOP2y ago
but how to make the end time the result of the start time added with the duration of other inputs?
Tin
Tin2y 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
Vp2y ago
fadil
fadilOP2y 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
Vp2y ago
When duration is enter, what will be the start_time.?
Tin
Tin2y ago
No, $get should be listed with the parameters as $set and $state then you can use it in your closure

Did you find this page helpful?