Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DateRangeSynth hydrate of all time preset #1172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joshhanley
Copy link
Member

The scenario

If a Livewire property is set to a DateRange with a preset of AllTime, then on the next request it fails to hydrate and throws the following error:

image
<?php

use Livewire\Volt\Component;
use Flux\DateRange;

new class extends Component {
    public DateRange $range;

    public function mount(): void
    {
        $this->range = DateRange::allTime('2018-01-01');
    }
}; ?>

<div class="flex">
    <flux:date-picker wire:model.live="range" mode="range" min="2018-01-01" with-presets/>
</div>

The problem

The issue is that we're not handling the AllTime preset in the hydrate method of DateRangeSynth.

if ($preset) {
    return DateRange::fromPreset(DateRangePreset::from($preset));
}

The solution

This PR adds a check for AllTime and handles it the same way that the hydrateType method does.

if ($preset) {
    if ($preset === DateRangePreset::AllTime->value) {
        return DateRange::allTime($value['start']);
    }

    return DateRange::fromPreset(DateRangePreset::from($preset));
}

Fixes #1160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Range date picker with allTime preset throws an Exception after selecting other presets
1 participant