malzariey / filament-daterangepicker-filter

MIT License
105 stars 46 forks source link

[V3] Dynamic schema not updating with live and afterStateUpdated #117

Closed GamendeBrian closed 2 months ago

GamendeBrian commented 2 months ago

In V 2.8, I used to have the following dynamic code:

DateRangePicker::make('date_range')
->required()
->label('Periode')
->live()
->afterStateUpdated(fn (DateRangePicker $component) => $component
    ->getContainer()
    ->getComponent('dynamicWeeksSection')
    ->getChildComponentContainer()
    ->fill()
),

Section::make('Weken')
->schema(function (Get $get) {

    if (!$get('date_range')) return [Forms\Components\Placeholder::make('')->hiddenLabel()->content('Selecteer eerst een periode.')];

    list($startDate, $endDate) = explode(' - ', $get('date_range'));

    $start = Carbon::createFromFormat('d/m/Y', trim($startDate))->startOfWeek();
    $end   = Carbon::createFromFormat('d/m/Y', trim($endDate))->endOfWeek();

    $week_range = collect($start->toPeriod($end))->mapWithKeys(function ($date) {
        return [$date->weekOfYear => $date->weekOfYear . '_' . $date->format('Y')];
    });

    foreach ($week_range as $week => $year) {
        $weeks[$week] = TextInput::make('weeks.week_' . $year)->label('Week ' . $week)->numeric()->required();
    }

    return $weeks;

})

This does the following:

https://github.com/user-attachments/assets/f94080b4-34b3-4160-81cc-613f5dc1309b

But now it doesn't work anymore:

https://github.com/user-attachments/assets/605aadd6-d8fd-430e-ba12-f495ae6cf9ee

afterStateUpdated does still trigger an update, so dd() does still work, but it seems like the schema() doesn't get updated after the initial load (even though it does?)

ajithMagic commented 2 months ago

Try re-publishing the view files by running the command php artisan vendor:publish --tag="filament-daterangepicker-filter-views". In my case I have deleted the folder entirely from the views and polished again fixed the issue.

GamendeBrian commented 2 months ago

I didn't publish it initially, but tried publishing with no luck.

I checked the published view and debugged for a bit and found the problem.

@teleport('body')
    <div id="{{$parentId}}">

    </div>
@endteleport

When I comment this out, the calendar works perfectly again!

See example:

https://github.com/user-attachments/assets/fe5e13db-a29e-4eae-8931-3257ff27c660

@malzariey, could you check?

malzariey commented 2 months ago

Thanks for raising the issue,

Addressed in version 3.0.1