laravel-fullcalendar icon indicating copy to clipboard operation
laravel-fullcalendar copied to clipboard

How to make click event?

Open hartantoignatiuss opened this issue 6 years ago • 5 comments

This is my code,

`<!doctype html>

<style>
    /* ... */
</style>
{!! $calendar->calendar() !!} {!! $calendar->script() !!} `

when i click the date, why i cannot alert something?

hartantoignatiuss avatar Apr 19 '18 04:04 hartantoignatiuss

SetCallbacks()

    public function getEvents() {

        $events = [];

        $data = Event::all();  // -->Your Model

        if($data->count()){

            foreach ($data as $key => $value) {

                $events[] = Calendar::event(
                    $value->title,
                    false,
                    new \DateTime($value->start_date),
                    new \DateTime($value->end_date),
                    $value->id,
                        [
                            'color' => $value->color,
                        ]
                );
            }
        }

        $calendar = Calendar::addEvents($events)
                            ->setOptions([
                                'eventLimit'     => 4,
                            ])->setCallbacks([
                                **//set fullcalendar callback options (will not be JSON encoded)**
                                'eventClick' => 'function(event) { 
                                        title= event.title; 
                                    

        return $calendar;
    }

Pablo-Araya avatar May 03 '18 14:05 Pablo-Araya

Working one! Remove {!! $calendar->script() !!} and add followings:

$(function() { ; $('#calendar-{{$calendar->getId()}}').fullCalendar({ selectable: true, header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, dayClick: function(date) { alert('clicked ' + date.format()); }, select: function(startDate, endDate) { alert('selected ' + startDate.format() + ' to ' + endDate.format()); } });

});

Mohammad-Yasin-Noori avatar Dec 27 '18 08:12 Mohammad-Yasin-Noori

The correct way seems to use "->setCallbacks"

For example:

$calendar = \Calendar::addEvents($events)
        ->setOptions([
            'firstDay' => 1,
            'editable'    => true,
            'selectable'  => true,
            'defaultView' => 'agendaDay',
            'minTime' => '05:00:00',
            'maxTime' => '22:00:00',
        ])
        ->setCallbacks([
            'eventClick' => 'function(event) { alert(event.title)}',
        ]);

This callback will popup the name of the clicked event

jestin-g avatar Apr 23 '19 08:04 jestin-g

hey @jestin-g ! Is it possible to include the js code from another js file instead of keeping it inside php code?

yogurtmale0 avatar Aug 06 '19 12:08 yogurtmale0

Working one! Remove {!! $calendar->script() !!} and add followings:

$(function() { ; $('#calendar-{{$calendar->getId()}}').fullCalendar({ selectable: true, header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, dayClick: function(date) { alert('clicked ' + date.format()); }, select: function(startDate, endDate) { alert('selected ' + startDate.format() + ' to ' + endDate.format()); } });

});

Solves my problem. Thank's

Aulerien avatar Dec 10 '19 10:12 Aulerien