nazar-pc / PickMeUp

Really simple, powerful, customizable and lightweight standalone datepicker
BSD Zero Clause License
615 stars 191 forks source link

Error at destroying the pickmeup calendar #153

Closed mystyroi closed 7 years ago

mystyroi commented 7 years ago

Hi,

When i try to suppress the pickmeup, i've used the destroy function destroy() on addEventListener('DOMContentLoaded',...) block :

pickmeup('.date').destroy(); (I've initialized well a pickemeup calendar)

The error is :

Uncaught TypeError: Cannot read property 'indexOf' of undefined

I want to destroy my calendar to make it reappear each time my first calendar is updated. I want to do this because once the pickemup object is created, its parameter are impossible to update/alter, so i want to delete first to create another with a var as parameter

Final objective : having two calendars, the second one has to disable days before the date choosen in the first calendar by the user.

COMPLETE CODE

<head>
    <title>Calendrier PickMeUp</title>

    <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>

    <link rel="stylesheet" href="http://nazar-pc.github.io/PickMeUp/css/pickmeup.css" type="text/css">
    <link rel="stylesheet" media="screen" type="text/css" href="http://nazar-pc.github.io/PickMeUp/demo/demo.css">
    <script type="text/javascript" src="http://nazar-pc.github.io/PickMeUp/js/pickmeup.js"></script>

    <script>
        addEventListener('DOMContentLoaded', function () {

            var element = document.getElementById("change");

            pickmeup('.dateBegin', {
                min : new Date,
                default_date : false,
                hide_on_select : true, 
                class_name : "beginning", 
                calendars : 3
            });

            element.addEventListener('pickmeup-change', function (e) {

                                // THE CONDITION WORKS WELL, THE CLASS IS OK, THE CALENDAR IS INITIALIZED, BUT THE DESTROY DOESNT WORK (event problem to catch the DOM element ?)
                if ($( ".ending" ).length) {
                    pickmeup('.dateEnd').destroy();
                }

                var newDate = e.detail.formatted_date;

                pickmeup('.dateEnd', {
                    date : newDate,
                    min : newDate,
                    default_date : false,
                    hide_on_select : true,
                    class_name : "ending", 
                    calendars : 3
                });

                pickmeup('.dateEnd').update();
            })
        });
    </script>
</head>

<body>
    <h1>My calendar</h1>

    <input  class="dateBegin" id="change" type="text" />

    <br></br>

    <input class="dateEnd" id="updated" type="text" />
</body>
nazar-pc commented 7 years ago

Can you put the source on jsfiddle or jsbin like in readme?: https://github.com/nazar-pc/PickMeUp#contribution

mystyroi commented 7 years ago

Okay, i've created it here https://jsfiddle.net/sL7a2uam/

Usage : Select the date from the first calendar, it will show the second calendar (which is the first time i generate the pickmeup object) but then, when i try to make a change of the date on the first calendar, the destroy function doesnt work)

I want to destroy to re-generate the second calendar because i don't succed to update dynamically the object parameters.

I've read a thread where you say to use the "render" in the parameter but it's the same, its not updating when i re-declare the pickemeup object (it doesnt take count)

nazar-pc commented 7 years ago

Just released 3.0.8 with fix for this issue. Let me know if you have any other issues.

mystyroi commented 7 years ago

It works great now like I was excepting, thank you !

nazar-pc commented 7 years ago

Good to hear, thanks for reporting with working demo!