Joro
Joro

Reputation: 321

Fullcalendar modal not showing jQuery

I have a full calender applicaiton. When I added code for showing a modal

function InitalizeCalendar() {
        try {

            var calenderEl = document.getElementById("calendar");
            if (calenderEl != null) {
                var calendar = new FullCalendar.Calendar(calenderEl, {
                    initialView: "dayGridMonth",
                    headerToolBar: {
                        left: 'prev,next,today',
                        center: 'title',
                        right: 'dayGridMonth,timeGridWeek,timeGridDay'
                    },
                    selectable: true,
                    editable: false,
                    select: function (event) {
                        onShowModal(event, null);
                    }
                });
                calendar.render();
            }

        }
        catch (e) {
            alert(e)
        }
    }

    function onShowModal(obj, isEventDetail) {
        $("#myModal").modal("show");
    }

nothing happends. In chrome, when i add a breakpoint to the function it gets triggered.

Anyone here knows what may cause this? I dont get much help to solving the problem in chrome console.

Upvotes: 1

Views: 169

Answers (1)

Lam Tran Duc
Lam Tran Duc

Reputation: 638

When clicking on the calendar, the modal doesn't show up, right?

Have you tried testing opening your modal with a button click.

I think the problem is related to your modal.

I simulated your code and added the modal. It works fine.

You can try like this:

function InitalizeCalendar() {
        try {
            var calenderEl = document.getElementById("calendar");
            if (calenderEl != null) {
                var calendar = new FullCalendar.Calendar(calenderEl, {
                    initialView: "dayGridMonth",
                    headerToolBar: {
                        left: 'prev,next,today',
                        center: 'title',
                        right: 'dayGridMonth,timeGridWeek,timeGridDay'
                    },
                    selectable: true,
                    editable: false,
                    select: function (event) {
                        onShowModal(event, null);

                    }
                });
                calendar.render();
            }

        }
        catch (e) {
            alert(e)
        }
    }

    InitalizeCalendar();

    function onShowModal(obj, isEventDetail) {
        $("#exampleModal").modal("show");
    }
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/main.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
        integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
        crossorigin="anonymous"></script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/main.min.js"></script>

<div id="calendar"></div>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>

Upvotes: 1

Related Questions