I've got an interesting issue occurring which I cannot seem to resolve using Select2 and FullCalendar.
Upon clicking an event, I am trying to pre-select the Select2 dropdown with what's in the database:
$('#calendar').fullCalendar({
eventClick: function(calEvent, jsEvent, view) {
$("#view_event").modal(); //launches bootstrap modal
$("#client_list_edit").select2();
$("#client_list_edit").select2("val", calEvent.ClientID);
}
});
Here's what I can't figure out: When I eventClick
the first time, it does not pre-populate with the information.
However, when I eventClick
a second time (or eventClick
any other event on the calendar for that matter) it works properly selects and displays the proper value.
I think this is working as you want:
http://jsfiddle.net/bU7wj/10/
HTML
<select id="events">
<option>??????</option>
<option value="00001">All Day Event</option>
<option value="00002">Long Event</option>
<option value="00003">Repeating Event</option>
<option value="00004">Repeating Event x</option>
<option value="00005">Meeting</option>
<option value="00006">Lunch</option>
<option value="00007">Birthday Party</option>
<option value="00008">Click for Google</option>
</select>
<div id="calendar"></div>
<div id="view_event" class="modal hide fade" tabindex="-1" role="dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<p>More info here…</p>
</div>
<div class="modal-footer">
<button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Ok</button>
</div>
</div>
JS
$(function() {
var events = $('#events');
var calendar = $('#calendar');
var modal = $('#view_event');
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
events.select2();
calendar.fullCalendar({
eventClick: function(event, jsEvent, view) {
modal.find('h3').text(event.title);
modal.modal();
events.select2('val', event.ClientID);
},
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: [
{
title: 'All Day Event',
start: new Date(y, m, 1),
ClientID: '00001'
},
{
title: 'Long Event',
start: new Date(y, m, d-5),
end: new Date(y, m, d-2),
ClientID: '00002'
},
{
id: 999,
title: 'Repeating Event',
start: new Date(y, m, d-3, 16, 0),
allDay: false,
ClientID: '00003'
},
{
id: 999,
title: 'Repeating Event x',
start: new Date(y, m, d+4, 16, 0),
allDay: false,
ClientID: '00004'
},
{
title: 'Meeting',
start: new Date(y, m, d, 10, 30),
allDay: false,
ClientID: '00005'
},
{
title: 'Lunch',
start: new Date(y, m, d, 12, 0),
end: new Date(y, m, d, 14, 0),
allDay: false,
ClientID: '00006'
},
{
title: 'Birthday Party',
start: new Date(y, m, d+1, 19, 0),
end: new Date(y, m, d+1, 22, 30),
allDay: false,
ClientID: '00007'
},
{
title: 'Click for Google',
start: new Date(y, m, 28),
end: new Date(y, m, 29),
url: 'http://google.com/',
ClientID: '00008'
}
]
});
});
UPDATE
I've added a Bootstrap's modal, the js library versions are:
try
$('#calendar').unbind('click').fullCalendar({
eventClick: function(calEvent, jsEvent, view) {
$("#view_event").modal(); //launches bootstrap modal
$("#client_list_edit").select2();
$("#client_list_edit").select2("val", calEvent.ClientID);
}
});
looks similar to a problem i had..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With