Calling `.flatpickr()` for the second time will blank-out previously set value
See original GitHub issueI have a page where form elements are dynamically pulled in and I call .flatpickr()
so appropriate fields are shown with calendar.
However, if there are any other existing fields with flatpickr they will get cleared.
Easy demo.
- Got to: https://chmln.github.io/flatpickr/examples/
- Set date on first input you see
- Run
$('.flatpickr').flatpickr()
- See field getting blanked
So it’s a bit unexpected and how do I work around this?
It doesn’t affect fields with ‘defaultDate’
Your Environment
- flatpickr version used: latest
- Browser name and version: n/a
- OS and version: ToasterOS
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top Results From Across the Web
The flatpickr Instance
Parses a date string or a timestamp, and returns a Date. redraw()#. Redraws the calendar. Shouldn't be necessary in most cases. set(option, value)#....
Read more >Falcon Sandbox v8.48.7 © Hybrid Analysis
https://www.bulbapp.com/u/regarder-cruella-2021-film-complet-hd-streaming%E2%80%99vf-francais. This report is generated from a file or URL submitted to this ...
Read more >frequent-classes - CodaLab Worksheets
... 10016 columns 9855 new 9855 head 9844 is 9802 publish 9705 time 9686 ui ... txt 6369 wide 6322 invisible 6307 second...
Read more >Module project index | Drupal.org
Extra Block Types (EBT): Call to Action ... Feeds Tamper: Entity Field Query by Field Collection ... Field Delimiter (Multi Value Field Formatter)....
Read more >Archives – CSS Weekly
An archive of all previously released newsletter issues. ... Why you should never use px to set font-size in CSS ... One Checkbox...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Bit of a hacky solution, but you could do something like this:
var timeFields = document.querySelectorAll(".timefield");
flatpickr(timeFields[timeFields.length-1]);
You’re able to pass an element to the initialize call as documented here: https://flatpickr.js.org/instance-methods-properties-elements/
This is my use-case:
.flatpickr()
defaultDate
won’t help here.I used bootstrap timepicker before and it would not re-initialize like that.
One work-around I can think of is to manually check if flatpicker is initialized on the element before initializing. Kinda icky though.