flatpickr / flatpickr

lightweight, powerful javascript datetimepicker with no dependencies
https://flatpickr.js.org
MIT License
16.07k stars 1.45k forks source link

Inputs with custom placeholder as value throw validation error during opening and closing calendar popup #3015

Open ldanut opened 2 months ago

ldanut commented 2 months ago

I have an input with value and placeholder attribute equals with "MMM/dd/yyyy" that is not supported by flatpickr. I added custom parsers and formatters to take into account this special value like:

        parseDate: (datestr, format) => {
            if(datestr === $this.displayPattern){
                return null;
            }

            return lw.lib.dateFns.parse(datestr, $this.displayPattern, new Date());
        },
        formatDate: (date, format, locale) => {
            if(!date || date.getTime() === 0){
                return $this.displayPattern;
            }
            return lw.lib.dateFns.format(date, $this.displayPattern);
        }

Everything works ok during initial calendar setup but when I just open the caledar and click outside of it I get following error:

Error: Invalid date provided: MMM/dd/yyyy t dates.js:81 q index.js:1651 en index.js:1722 en index.js:72 en index.js:1977 tn index.js:1994 nn index.js:2018 initialize flatdateinput.js:39

ldanut commented 2 months ago

With my changes all tests passes.