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 input clearable button to also dispatch change event #1170

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

Conversation

joshhanley
Copy link
Member

@joshhanley joshhanley commented Feb 24, 2025

The scenario

If you have a date pciker with an input that has the clearable attribute, currently pressing the clear button will clear the input value but won't update the value stored by Livewire.

image
<?php

use Livewire\Volt\Component;

new class extends Component {
    public $date;
};
?>

<div>
    <flux:text>Date: {{ $date }}</flux:text>
    <flux:date-picker
        wire:model.live="date"
    >
        <x-slot name="trigger">
            <flux:date-picker.input clearable />
        </x-slot>
    </flux:date-picker>
</div>

The problem

The problem is that the clear button only dispatches an input event but the date picker is listening for a change event on the input.

The solution

The solution is to update the clearable button to also dispatch a change event, which I have done in this PR. I also refactored the clear button to make it more efficient and readable.

image

Fixes #1157

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.

Binded model of datepicker with wire:model.live and date-picker.input is not cleared when using clearable=true
1 participant