开发者

How to cancel old selection in fullCalendar?

开发者 https://www.devze.com 2023-02-04 05:11 出处:网络
I use jQuery fullCalendar (http://arshaw开发者_如何转开发.com/fullcalendar/docs/selection/unselectAuto/)

I use jQuery fullCalendar (http://arshaw开发者_如何转开发.com/fullcalendar/docs/selection/unselectAuto/)

I use Selectable version of this calendar (http://arshaw.com/js/fullcalendar/demos/selectable.html)

It's working fine however I want to cancel/delete my old selections if I continue selecting new dates.

Lets say I chose 1 Jan and gave a title to it. When I try to select 2 Jan, I want to see only 2 Jan selection. I thought unselectAuto is for this but I couldnt manage to make it work :(

Any ideas?

I used unselectAuto right under selectable: true, unselectAuto: true,


First it's still necessary to use the $('#yourCalendar').fullCalendar('unselect'); function.

The second thing that I needed to do, was to specify how the unselect callback was going to behave (when setting up the fullcalendar options). For me I had to unbind the submit button from my form

unselect: function(){
    $('#submitButton').unbind();
},

It worked great!

I was able to reach this conclusion after reading this post "multiple events created"


u can try this way, this works for me :)

 var liveDate = new Date(); // current Date
 var calendar = $('#calendar').fullCalendar({
         select: function (startDate, endDate) {
                    if (liveDate > startDate) {
                      alert('Selected date has been passed');
                      return false;
                  } else {
                           //do your wish
                  }
         calendar.fullCalendar('unselect');
    }
});


Had the same problem but my user was interfacing directly with the calendar and multiple events were being generated. ie. not through a form with a button and therefore nothing to "unbind" as many of the previous solutions.

To only allow one selection and to clear previous submissions I changed the select function as follows:

select: function(start, end) {
   var title = "Desired Booking";
   var eventData;
   eventData = {
       title: title,
       start: start,
       end: end
   };
 $('#calendar').fullCalendar('renderEvent', eventData, true);                                                },

select: function(start, end) {
   $('#calendar').fullCalendar('removeEvents');
   $('#calendar').fullCalendar('rerenderEvents')
   var title = "Desired Booking";
   var eventData;
   eventData = {
       title: title,
       start: start,
       end: end
   };
 $('#calendar').fullCalendar('renderEvent', eventData, true);                                                },

This did the trick for me.


I had problems with unselectAuto also. Sometimes it would unselect when I didn't want it to, and sometimes it would NOT unselect when I DID want it to. My solution was to manually trigger the unselect method.

Here's how to unselect all currently selected:

$('#yourCalendar').fullCalendar('unselect');

You can put this line of code inside custom jQuery events that you bind outside of the plugin. You can also include it in fullCalendar callbacks, etc...

Hope this helps.

Scott


Here is an exemple of Version 5 doing the unselect You could do it by :

const calendarApi = selectInfo.view.calendar;

calendarApi.unselect(); // clear date selection


Use this code

 $('#trainings_modal').on('hidden', function () {
        $('#trainings_modal *').unbind(); // Unbind all events
 });

Unbind on hide form with any method (i.e esc press, or out key)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号