themesberg / flowbite-datepicker

A Tailwind CSS datepicker built with vanilla JavaScript
https://flowbite.com/docs/components/datepicker/
MIT License
136 stars 40 forks source link

Setting options when using Livewire #28

Open blunde opened 8 months ago

blunde commented 8 months ago

How can I set options on a datepicker that is already initialized ?

Using Laravel 10, Livewire 3, npm

cinderjk commented 7 months ago

The documentation is clear, you just need extra code to enable in livewire 3

page.blade.php

<script data-navigate-once>
    document.addEventListener('livewire:navigated', () => {
        const Datepicker = document.getElementById('date');

        if (!Datepicker) return;

        new Datepicker(Datepicker, {
            format: 'yyyy/mm/dd',
            buttons: true, // not working
            autohide: true,
            title: 'This is a datepicker',
        }); 
    });
</script>

app.js

import Datepicker from 'flowbite-datepicker/Datepicker';

window.Datepicker = Datepicker;

Livewire.start()