fetch disabledDates() Data ->afterStateUpdated in other formfield

Hello folks, I'm currently creating a small rental system where I assign different booking positions to bookings (BookingTable) via a repeater. I can choose one item per position and have a DateRangePicker from Filament Plugin by Malzariey. Now to the problem: When I change the item, a "->afterStateUpdated"- function must be triggered so that the data in the DateRangePicker for the ->disabledDates() function is updated. The goal for this item is to display all already occupied periods from the database in the calendar. So I have to trigger an event as soon as the item changes or a new position is added. In addition, for existing bookings, the calendar must of course display the disabled dates to match the item. If items and periods are in the database, then this will also be reflected. However, I don't know how to configure a component with Filament so that I can, for example, trigger an AJAX after a stateUpdate to dynamically fetch the data. Can someone help me with that? Please. Screenshot 1 and 2 shows an existing booking and its processing. The disbledDates() are shown for the item:
No description
No description
1 Reply
Gojim/Paul
Gojim/Paul4d ago
Screenshot 3 shows a new Position. Select::make('item_id') ->label('Artikel') ->options(Item::query()->pluck('name', 'id')) ->required() ->reactive() ->columnSpan([ 'md' => 5, 'lg' => 2, ]) ->afterStateUpdated(fn ($state, Set $set) => $set('price', Item::find($state)?->price ?? 0)) ->afterStateUpdated(function (Get $get, Set $set, $state) { $set('date_range', null); self::updateTotals($get, $set); }) ->searchable(), DateRangePicker::make('date_range') ->label('Buchungszeitraum') ->required() ->disableClear() ->autoApply() ->columnSpan([ 'lg' => 3, ]) ->disabledDates(function ($get) { $itemId= $get('item_id'); $bookedDates = BookingPosition::where('item_id', $itemId)->get(); $disabledDates = []; foreach ($bookedDates as $booking) { $from = Carbon::parse($booking->from_date); $to = Carbon::parse($booking->to_date); while ($from <= $to) { $disabledDates[] = $from->toDateString(); $from->addDay(); } } return $disabledDates; })
No description
Want results from more Discord servers?
Add your server