FullCalendar open bootstrap modal on dayClick

半腔热情 提交于 2019-11-30 13:30:21

问题


I want to open a bootstrap modal when users click on a day in fullCalendar. I have look over dayClick event but can't figure out how to call the model.

dayClick: function(date, jsEvent, view) {
     // call the model 
},

Normal link to call a bootstrap model

<a href="#" data-toggle="modal" data-target="#myModal"..................../>

EDIT :

I use only 1 bootstrap model for all my needs and simply change the content. The way I do this is by calling a href .. so my link looks like :

<a href="<?php echo site_url('model/add') ?>" data-toggle="modal" data-target="#myModal" role="button" class="btn-u btn-block"> Add</a>

回答1:


If someone else needs to open fullCalendar events in bootstrap model I found the way to do it :

Add :

        eventClick:  function(event, jsEvent, view) {
            $('#modalTitle').html(event.title);
            $('#modalBody').html(event.description);
            $('#eventUrl').attr('href',event.url);
            $('#calendarModal').modal();
        },

And the model :

<div id="calendarModal" class="modal fade">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span> <span class="sr-only">close</span></button>
            <h4 id="modalTitle" class="modal-title"></h4>
        </div>
        <div id="modalBody" class="modal-body"> </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>
</div>
</div>



回答2:


The following should work:

dayClick: function(date, jsEvent, view) {
    $("#myModal").modal("show");
},

Assuming that the ID of your modal is in fact myModal. .modal() is the JavaScript method used by bootstrap to manipulate modals... Similarly, you can close the modal using $("#myModal").modal("hide")...




回答3:


Another way is upon calendar redering:

eventRender: function(event, element) {
                        element.attr('data-toggle', "modal");
                        element.attr('data-target', "#sched-modal");
                        element.attr('href', "/details");
                    }



回答4:


i've got the same issue but for some reason, only the 'text' method worked for me.

$('#calendar').fullCalendar({
    dayClick: function(date, jsEvent, view) {
        alert('Clicked on: ' + date.format());
        $('#modalTitle').text(date.format());
        $('#fullCalModal').modal('show');
    }
});


来源:https://stackoverflow.com/questions/29072645/fullcalendar-open-bootstrap-modal-on-dayclick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!