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
You can use $get and $set closures
And
afterStateUpdated()
input method
Write afterStateUpdated(function ($state, $set)
on your start_time
input.
Then, in you closure use $set('end_time',$state)
but how to make the end time the result of the start time added with the duration of other inputs?
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')
You can check more here.. fadil https://beta.filamentphp.com/docs/3.x/forms/advanced/#reactive-forms-cookbook
he/she tag v3...
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?
When duration is enter, what will be the start_time.?
No, $get should be listed with the parameters as $set and $state
then you can use it in your closure