2

I am using flatpickr datepicker to allow users to choose a date. However, the datepicker dialog is not showing up in most of the cases, even though the input field is visible when I inspect. Moreover, even though I am not using flatpickr-months, it shows up on the UI in a very weird manner. What could be causing the issue?

JQuery

flatpickr('.flatpickr.js-flatpickr-date', {
      enableTime: false,
      dateFormat: "Y-m-d"
    });

HTML

<input type="date" class="flatpickr js-flatpickr-date" name="date-planted" placeholder="Select date here"/>

Output

The flatpickr datepicker does not show up.

enter image description here

This is the flatpickr-months output I am talking about which is nowhere specified by me in the code and is showing up unnecessarily in weird manner

enter image description here

2 Answers 2

1

In order to use the month and year picker you need to use the Flatpickr option static: true. This way it will not hide behind the other elements.

$(document).ready(function() {
  const my_flatpickr= $('#my_flatpickr').flatpickr({
    //static: position the calendar inside the wrapper and next to the input element*.
    static: true
  });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! That was the problem in my case!
0

Apparently, the styles for the flatpickr were not loaded.

Depending on how you installed `flatpickr`, you would need to include the flatpickr CSS stylesheet to resolve the issue.
You might simply need to include CSS with the <link> HTML tag:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">

or add to assets:

@import 'flatpickr/dist/flatpickr.css';

I was looking to install the flatpickr with Laravel. Here are the sources I used to resolve the issue:
How do I load the CSS for flatpickr when I use npm to install it in Laravel?
Laravel + Flatpicker: How to Install using NPM

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.