Getting start and end dates from Fullcalendar

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
josejad
User
Posts: 140
Location: Spain

Getting start and end dates from Fullcalendar

Post by josejad »

Hi there:

I need to get the first and last dates shown on the calendar.

When I shown the calendar with a custom template , I could get the dates with:

	var date_from =calendar.view.activeStart;
	var date_to= calendar.view.activeEnd;

But now I don't know how to do it. I've tried adding a console.log after this code in Server->Global->All Pages->Page_Head

echo <<<EOD
<script>
loadjs.ready("jquery", () => {
    $(document).on("calendar", function (e, args) {
        const BtnPlaniDiaria = {		
            BtnPlaniDiaria: {
                text: 'Enviar',
                click: function() {
                    alert('testing');				
                }
            }
        }; 
        args.options.customButtons = Object.assign(args.options.customButtons, BtnPlaniDiaria);
        console.log(args.options); // View all options
    });
});
</script>
EOD;

but I can't find activeStart or activeEnd

Any ideas?
Thanks¡


arbei
User
Posts: 9719

Post by arbei »

If you want to set calendar options, you may read View-Specific Options.


josejad
User
Posts: 140
Location: Spain

Post by josejad »

Thanks, I've set some options the way you teach me in other thread.

But now I don't want to set any options. I want to read the first date shown and the last one.

i.e. you click several times the "< >" buttons in the fullcalendar, to navigate between dates, showing i.e. weeks, from monday to sunday, 2024/06/10 to 2024/06/16... click next, then show from 2024/06/17 to 2024/06/23...

Then I want to know the activeStart and activeEnd..

It can be read from the https://fullcalendar.io/docs/view-object, but I cant reach them "console.log(args.view);" shows "undefined"


arbei
User
Posts: 9719

Post by arbei »

There is no such property as args.view. (If you want to set views, you can add args.options.views though, but you want to read.) You may read FullCalendar's docs on View Object:
This information about the current view is passed into nearly every handler.


josejad
User
Posts: 140
Location: Spain

Post by josejad »

Hi, the trick was using "currentCalendar.view.activeStart"

echo <<<EOD
<script>
loadjs.ready("jquery", () => {
    $(document).on("calendar", function (e, args) {
        const BtnPlaniDiaria = {		
            BtnPlaniDiaria: {
                text: 'Enviar',
                click: function() {
                    alert(currentCalendar.view.activeStart);				
                }
            }
        }; 
        args.options.customButtons = Object.assign(args.options.customButtons, BtnPlaniDiaria);
        console.log(args.options); // View all options
    });
});
</script>
EOD;

Post Reply