Setting locale doesn't take modification - javascript

In advance, excuse my English!
I've been trying to understand for several hours why changing the locales setting don't work in my code.
I would like to switch my calendar (from fullcalendar.io) in "Fr", so I put the right language .js file in a folder and tried to point my page on it.
Off, it does not take my modification in the code.
Do you have an idea or a track to propose to me?
I warn, I'm not necessarily really friend with the code in general even if I do the max ^^
Thank you!
Here's a part of my code:
<script src='./packages/core/locales/fr.js'></script>
document.addEventListener('DOMContentLoaded', function() {
var initialLocaleCode = 'fr';
var localeSelectorEl = document.getElementById('locale-selector');
var calendarEl = document.getElementById('calendar');
var calendar = $('#calendar').fullCalendar({
plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list' ],
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay,listMonth'
},
locale: initialLocaleCode,
buttonIcons: false,
weekNumbers: true,
navLinks: true,
editable: true,
eventLimit: true, // allow "more" link when too many events
events: "events.php",

Edit with the fix:
I finally deleted everything and redo my php page with the right code from FullCalendar.
I think, as you said, have mixed code from an older version with that from a newer version. So I took the basic script from the site FullCalendar and delivered what interests me!
document.addEventListener('DOMContentLoaded', function() {
var initialLocaleCode = 'fr';
var localeSelectorEl = document.getElementById('locale-selector');
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
plugins: [ 'interaction', 'dayGrid', 'timeGrid', 'list' ],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,list'
},
locale: initialLocaleCode,
buttonIcons: false,
weekNumbers: true,
navLinks: true,
editable: true,
eventLimit: true, // allow "more" link when too many events
events: "events.php",
Thank you all for your help!

May be you want to change the language in calendar.
Try:
lang: 'fr'
Be sure you have also inserted the right script for it. Arrange the path according to your folders:
<script src='fullcalendar/lang-all.js'></script>

Related

Too many Events are loaded when calendar is initialized from json

I have the following code...
$(document).ready(function() {
// page is now ready, initialize the calendar...
var calendar = $('#fullCalendar').fullCalendar({
// put your options and callbacks here
// height: 600,
// aspectRatio: 2,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
navLinks: true, // can click day/week names to navigate views
editable: false,
eventLimit: true, // allow "more" link when too many events
events: <?php echo $myjson ?>,
This loads all of the events, not just the ones needed for the monthly view. I cannot figure out how to set the start and end params to limit the event loading. I would greatly appreciate some insight on this.

Reference to a calendar object

I need to reference an fullcalendar object – to change contents or options after intialisation - , but I always get the error message.
I first tried the javascript initialisation and then the jQuery version. I've tried "calendar.refech()" and "calendar.fullcalendar.refetch()" and "$.(#calendar)('refetchEvents')"
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
$(function() {
$('#calendar').fullCalendar({
plugins:
[ 'interaction', 'dayGrid', 'timeGrid' ,'list'],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
locale: 'de',
defaultDate: heute,
{…}
editable: true,
eventLimit: true,
events: 'load.php',
})
});
});
$('#calendar').getOption('locale');
The last line in code produces the errror: "Uncaught TypeError: $(...) is not a function
As noted in your code, calendarEl is initialized but never used.
Basically, you can initialize the main Calendar object out of eventListener DOMContentLoaded, and utilize it as global within that page like the following code:
var myCalendar;
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var myCalendar = new FullCalendar.Calendar(calendarEl, {
plugins:
[ 'interaction', 'dayGrid', 'timeGrid' ,'list'],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
locale: 'de',
defaultDate: heute,
{…}
editable: true,
eventLimit: true,
events: 'load.php'
});
myCalendar.render();
});
The initialization of Calendar object is provided in this link.

Sync FullCalendar With Another FullCalendar Same Page

Using FullCalendar I am able to display 2 calendars on the same page. Calendar1 has all the controls to switch views from Day, Week, Month, Year plus the arrows to go forward/backwards. Calendar2 is a listMonth with no controls showing. It works fine on load but I would like it to change when Calendar1 changes from month to month or year to year.
Is this possible? I haven't found anything that would allow me to change the listMonth when the month/year changes on Calendar1.
jQuery(document).ready(function () {
$('#calendar1').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaDay,agendaWeek,month,listYear'
},
views: {
listYear: { buttonText: 'Year'}
},
navLinks: true, // can click day/week names to navigate views
selectable: true,
selectHelper: true,
editable: false,
eventLimit: true, // allow "more" link when too many events
events: "CalendarData.ashx",
eventColor: '#038ddd'
});
$('#calendar2').fullCalendar({
header: {
left: '',
center: '',
right: ''
},
views: {
listMonth: { buttonText: 'Month' }
},
defaultView: 'listMonth',
navLinks: true, // can click day/week names to navigate views
selectable: true,
selectHelper: true,
editable: false,
eventLimit: true, // allow "more" link when too many events
events: "CalendarData.ashx",
eventColor: '#038ddd'
});
});
I had a need to implement this recently to sync a grid and list view. I came across this question, but the suggested comments no longer appear valid. Here is a simple solution I used.
This is the simple html container for both calendars.
<div>
<div id="calendarGrid"></div>
<div id="calendarList"></div>
</div>
Below is the javascript code to hook into the "datesSet" method that triggers as the user navigates through the calendar and sets the date for the "other" calendar to keep it in sync, including a date comparison to prevent an infinite loop.
var calendarElGrid = document.getElementById('calendarGrid');
var calendarElList = document.getElementById('calendarList');
var calendarGrid = new FullCalendar.Calendar(calendarElGrid, {
initialView: 'dayGridMonth',
datesSet: function (info) {
syncCalendar(calendarList, info.start);
}
});
calendarGrid.render();
var calendarList = new FullCalendar.Calendar(calendarElList, {
initialView: 'listMonth',
datesSet: function (info) {
syncCalendar(calendarGrid, info.start);
}
});
calendarList.render();
function syncCalendar(otherCalendar, startDate) {
if (otherCalendar.getDate().toDateString() != startDate.toDateString()) {
otherCalendar.gotoDate(startDate);
}
}
Solution is based off of v6.0.2 documentation here:
https://fullcalendar.io/docs/datesSet

I want to display event dynamically in fullcalendar 3.0.1

below is my code. i don't know why the calendar are working but no event displayed. I very appreciate your help.
var eventSTR = [{start: '2016-11-21',end: '2016-11-23',overlap: false,rendering : 'background', color: '#ff9f89'},];
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next',
center: 'title',
right: 'month',
},
defaultDate: today,
navLinks: false, // can click day/week names to navigate views
businessHours: true, // display business hours
editable: false,
event : eventSTR
});
});
You're 99% there, just missing 2 things
1) you need to set the today variable before you set the document ready function:
var today = new Date();
2) you've misspelled the events property. You have:
event : eventSTR
it should read:
events : eventSTR

Render events as disabled fields

I am working on a project where users create appointments using fullcalendar. Users can only create appointments on those timeslots(30min) that are available. These events are coming from a file named as events_json.php. i am including this file in like this
$(document).ready(function() {
$myCalendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaWeek,agendaDay'
},
theme: true,
selectable: true,
selectHelper: true,
height: 500,
events: 'JSON/events_json.php',
select: function(start, end, allDay) {
//$('#eventStart').datepicker("setDate", new Date(start));
/*$('#eventStart').datepicker({
dateFormat: 'dd-mm-yy'
},new Date(start));
$('#eventEnd').datepicker({
dateFormat: 'dd-mm-yy'
},new Date(end));*/
$('#calEventDialog').dialog('open');
},
editable: false
});
Now the events are showing but i don't want to show the user that, user should only see the time-slots as disabled and the free time-slots as links with title as "Book".
I found the renderEvent in documentation but couldn't get around it.
EDIT 1
The events_json.php is sending events like this
The file is sending events like this,
$output_arrays = array(array("title"=>"Happy Hour", "start"=>"2016-01-13T07:00:00-05:00"),
array("title"=>"Click for Google", "start"=> "2016-09-02")
);
echo json_encode($output_arrays);
In order to show existing events as "taken", you can handle the eventDataTransform event.
$(document).ready(function() {
$myCalendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'agendaWeek,agendaDay'
},
theme: true,
selectable: true,
selectHelper: true,
height: 500,
events: 'JSON/events_json.php',
eventDataTransform: function(event) //this is called once for each event returned in the JSON
{
event.title = "Taken";
return event;
},
select: function(start, end, allDay) {
//$('#eventStart').datepicker("setDate", new Date(start));
/*$('#eventStart').datepicker({
dateFormat: 'dd-mm-yy'
},new Date(start));
$('#eventEnd').datepicker({
dateFormat: 'dd-mm-yy'
},new Date(end));*/
$('#calEventDialog').dialog('open');
},
editable: false
});
N.B. the "eventRender" you mention isn't an event, it's a method you can call to add new events to the calendar on the client-side. That's probably why it didn't help you in this situation. It might be more helpful when you want users to book into a slot - handle the "select" event (as you're doing already) and then use renderEvent to create a new appointment on the calendar. You can control the duration and all other properties of the event that gets added.

Categories