flatpickr icon indicating copy to clipboard operation
flatpickr copied to clipboard

Allowinput && Invalid date provided

Open sylvaincaillot opened this issue 3 years ago • 2 comments

Using flatpickr 4.6.11, I have the following code:

  date_from = flatpickr("#myDatePickerFrom", {
        locale: 'es',               
        altInput: true,
        altFormat: "F j, Y",
        dateFormat: "m/d/Y H:i:S",
        allowInput: true,
        onOpen: function (selectedDates, dateStr, instance) {
            instance.setDate(instance.input.value, false);
        }
    });

I can select a date using the calendar and it is displayed in the correct format (Marzo 22, 2022) but when I try to enter a date manually, I keep getting "Invalid date provided".I tried 01/25/2002, 25/01/2022, 2022/01/25, 2022-01-25 and many other and keep getting the same error. What I am doing wrong? Do I need to specify the format of the input anywhere?

Thank you, Sylvain

sylvaincaillot avatar Mar 22 '22 20:03 sylvaincaillot

It's probably the same problem I've just been struggling with. In my case, it worked when I pressed <Enter> after entering the date manually, but not when I just left the input field or submitted the form.

The problem is that the "fake" format is shown in a new input field, while the original one is transformed into a hidden input field. They are synchronized when using the date picker or when pressing <Enter> after a manual input, but not when just typing into the input field, as it seems.

I'm working with Livewire and Alpine, and I had to jump through several loops to make this work; amongst other things I had to convert the German date string back to the standard date format 'Y-m-d' myself.

If someone is interested, I can post my flatpickr Blade component here (using Laravel, Livewire, and Alpine, as I said).

enigmatic-user avatar Jun 28 '22 19:06 enigmatic-user

That would be super handy if you could!

If someone is interested, I can post my flatpickr Blade component here (using Laravel, Livewire, and Alpine, as I said).

@enigmatic-user

uWotM82024 avatar Sep 28 '23 14:09 uWotM82024