Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot open calendar when DOM ist removed #15

Closed
louis123562 opened this issue May 3, 2021 · 5 comments
Closed

Cannot open calendar when DOM ist removed #15

louis123562 opened this issue May 3, 2021 · 5 comments

Comments

@louis123562
Copy link

louis123562 commented May 3, 2021

Hey,

we sometimes need to replace the whole body-element with new html.

When i try to open up the calendar (by creating a new constant) it wont show up.

Do you have a fix for this?

Here is an example (with jquery):

 <!DOCTYPE html>
 <html lang="de">
 
 <head>
     <meta charset="utf-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <title>Titel</title>
 
     <script src="https://code.jquery.com/jquery-3.6.0.min.js"
         integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
 
     <link rel="stylesheet" href="node_modules/mc-datepicker/dist/mc-calendar.min.css">
     <script src="node_modules/mc-datepicker/dist/mc-calendar.min.js"></script>
 
 </head>
 
 <body>
 
     <div class="form-field">
         <label class="form-field__label">Datepicker Demo</label>
         <input id="datepicker" type="text">
     
         <button id="delete">delete</button>
         <button id="open">open again - not working</button>
     </div>
 
 
     <script>
         $(function () {
         
             $(document).on("click", "#datepicker", function () {
                 const test = MCDatepicker.create({
                     dateFormat: 'DDD.DD.MM.YYYY'
                 });
             
                 test.open();
             })
         
             $(document).on("click", "#delete", function () {
                 $(".mc-calendar").remove();
             })
         
             $(document).on("click", "#open", function () {
                 const test = MCDatepicker.create({
                     dateFormat: 'DDD.DD.MM.YYYY'
                 });
             
                 test.open();
             })
         
         });
     </script>
 </body>
 
 </html>
@mikecoj
Copy link
Owner

mikecoj commented May 5, 2021

Hey,
just pushed a new commit to the develop branch that should fix this.
Check out this example: https://jsfiddle.net/z8xv9n61/8/

@louis123562
Copy link
Author

louis123562 commented May 7, 2021

Thank you Mike,

but i think there is a little bit more work (maybe on my side?) to do - or i just dont get it running :)

I made a fiddle which represents my problem: https://jsfiddle.net/louis123562/s405xkfm/15/

I know that replacing the whole body is not good way, but it is as it is at the moment.

The calender is shown without css styles (in fiddle), but in my real project it does not appear in the DOM anyway (after replacing the body).

Can you help me out on this?

@mikecoj
Copy link
Owner

mikecoj commented May 7, 2021

The problem with the jsfiddle is that you are writing the whole code in the HTML area, but in that area, you should add only the content of the body element, everything else has its own dedicated area.

I've saved the code in an HTML file, and opened it, and that works as well.
Probably you're missing something in your code.

@louis123562
Copy link
Author

louis123562 commented May 10, 2021

Hey Mike,

i rewrited my code on this weekend, so the body will not be emptied.

It should fix my problem, i will try out later today :)

@louis123562
Copy link
Author

Yep, it works like a charm now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants