DatePicker -> disableDates only when a model is loaded

I've the following use case where Date Picker is disabled when a vehicle is not selected.
->disabled(function (Closure $get) {
return $get('vehicle_id') === null;
})
->disabled(function (Closure $get) {
return $get('vehicle_id') === null;
})
But then later on, when a vehicle is selected, it needs to supply array of dates on disableDates
->disabled(function (Closure $get) {
return $get('vehicle_id') === null;
})->disabledDates(
$this->vehicle->booked_dates
)
->disabled(function (Closure $get) {
return $get('vehicle_id') === null;
})->disabledDates(
$this->vehicle->booked_dates
)
The problem is since we disable it based on vehicle is not selected yet, $this->vehicle is a null and therefore does not return an array of booked dates. Is there a way where I can disabledDates to DatePicker via the following SelectField where choosing the vehicle happens:
Forms\Components\Select::make('vehicle_id')
->helperText('The vehicle that is ordered in this booking')
->relationship('vehicle', 'name', fn (Builder $query) => $query->where('vendor_id', $this->vendor->id))
->preload()
->lazy()
->required()
->disabledOn('edit'),
Forms\Components\Select::make('vehicle_id')
->helperText('The vehicle that is ordered in this booking')
->relationship('vehicle', 'name', fn (Builder $query) => $query->where('vendor_id', $this->vendor->id))
->preload()
->lazy()
->required()
->disabledOn('edit'),
Thanks Pram.dev
1 Reply
toeknee
toeknee2y ago
Why not populate the list once it has been updated?
->reactive()
->disabled(fn(Closure $get) => $get('vehicle_id') === null)
->disabledDates(fn($record) => $record->vehicle->booked_dates)
->reactive()
->disabled(fn(Closure $get) => $get('vehicle_id') === null)
->disabledDates(fn($record) => $record->vehicle->booked_dates)
Want results from more Discord servers?
Add your server