Skip to content

Datepicker render duplicates #1040

@oostapov

Description

@oostapov

maryUI version

2.4.0

daisyUI version

5.0.35

Livewire version

3.6.3

What browsers are affected?

Firefox, Chrome, Safari, Microsoft Edge

What happened?

If a page has one or several DatePicker components on every page update a new instance(s) of the flatpickr is rendered.

The reason why it happens is the random key assigned to the component View/Components/DatePicker.php (108)

    public function render(): View|Closure|string
    {
        return <<<'BLADE'
            <div wire:key="datepicker-{{ rand() }}">
                @php
                    // We need this extra step to support models arrays. Ex: wire:model="emails.0"  , wire:model="emails.1"
                    $uuid = $uuid . $modelName()
                @endphp

The following code fixes the issue:

    public function render(): View|Closure|string
    {
        return <<<'BLADE'
            @php
                // We need this extra step to support models arrays. Ex: wire:model="emails.0"  , wire:model="emails.1"
                $uuid = $uuid . $modelName()
            @endphp
            <div wire:key="datepicker-{{ $uuid }}">

Metadata

Metadata

Assignees

No one assigned

    Labels

    helpHelp me!

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions