I would like to calculate the duration mesuring the diferance in time between two imput fields. And pass the result to a placeholder.
I have a laravel 10.x using filament PHP 3.1 on the form builder for my model resource I have two timepiker fields and a PlaceHolder.
I can do something similar populating a textfield and setting it to disaibled but i feel like this should be cleaner.
However its not working. Ive also tryed parcing the time instances and no matter what I do I either get a trailing error, nothing happenss.
Im guessing that the problem is that I cant use SET on a placeholder. Any ideas?
use Carbon\Carbon;
....
Forms\Components\TimePicker::make('startTime')->live()
Forms\Components\TimePicker::make('endTime')
->live()
->afterStateUpdated(function (Get $get, Set $set) {
if ($get('dia_hora_inicio') !== '' && $get('dia_hora_final') !== '') {
$startTime = $get('startTime');
$endTime = $get('endTime');
// Convert starting and ending times to Carbon instances
$startDateTime = Carbon::createFromFormat('H:i:s', $startTime);
$endDateTime = Carbon::createFromFormat('H:i:s', $endTime);
// Calculate the time difference
$timeDifference = $endDateTime->diff($startDateTime)->format('%H:%I:%S');
// Set the value of the 'duracion' field to the calculated time difference
$set('duration', $timeDifference);
}
return '';
}),
// Target field
Forms\Components\PlaceHolder::make('duration')
->live()
->visible(function (Get $get) {
// Get value from venta_lineas_id
$startDateTime = $get('startTime');
$endDateTime = $get('endTime');
$date = $get('date');
return $date && ($startDateTime !== '' && $endDateTime !== '');
})
->content('foo'),
Any ideas?