Send fullcalendar event data to modal window

Asked

Viewed 72 times

0

I have a fullcalendar with the following events:

events: [
    {
      id: 1,
      title: 'Evento 01',
      start: '2020-02-06'
    },
    {
      id: 2,
      title: 'Evento 02',
      start: '2020-02-19'
    },
    {
      id: 3,
      title: 'Evento 03',
      start: '2020-02-25'
    }
]

When we click on the event a modal is displayed:

eventClick:  function(event) {
    var id = event.event.id;
    $('#modal').modal();
}

Externally, uncoupled, another js, specific for this purpose, takes charge of loading the data in the modal via ajax:

$('#modal').on('show.bs.modal', function () {
    //Ajax
});

How can I send the "Event" data from Function "eventClick" to the js that calls ajax when the modal window opens?

1 answer

1


I ended up finding the solution by setting the data-id attribute:

eventClick:  function(event) {
    $('#modal').attr('data-id', event.event.id).modal();
}

And taking that information from the other document:

('#modal').on('show.bs.modal', function () {
    var id = $(this).data("id");
    //Ajax
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.