question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling `.flatpickr()` for the second time will blank-out previously set value

See original GitHub issue

I 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.

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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kisukacommented, Jun 3, 2018

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/

1reaction
GBHcommented, Jan 5, 2018

This is my use-case:

  • Have few datepicker fields that I spent 3 hours populating
  • Ajax brings in more form fields that I need to .flatpickr()
  • All my existing form fields are blanked. defaultDate won’t help here.
  • Cry

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found