Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

javascript - how to display all details of selected event immediately on fullcalendar

I have the following html page that uses fullcalendar:

document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');
  var calendar = new FullCalendar.Calendar(calendarEl, {
    initialView: 'timeGridWeek',
    editable: true,
    headerToolbar: {
      start: 'prev,next today',
      center: 'title',
      end: 'dayGridMonth,timeGridWeek,timeGridDay'
    },
    selectable: true, //can click to set event
    selectMirror: true, // so it's solid 
    unselectAuto: false, //if you click outside calendar, event doesn't disappear, but if you click inside calendar, event still disappears

    editable: true,
    eventStartEditable: true,
    eventResizableFromStart: true,
    eventDurationEditable: true,
    select: function(selectionInfo) {
      calendar.addEvent({
        title: 'dynamic event',
        start: selectionInfo.start,
        end: selectionInfo.end //need these and not endTime/startTime, otherwise they won't re-render
      });
    }



  });
  calendar.render();

});
<!DOCTYPE html>
<html>

<head>
  <title>Fullcalendar Demo</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/main.min.css" />
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/main.min.js"></script>
</head>

<body>
  <div id="calendar"></div>
</body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You just need to run calendar.unselect(); after you've added the event so that the element which visualises the selection (which because of the selectMirror option is solid rather than transparent) doesn't overlay on top of the rendered event.

Selections are not cleared automatically until you click somewhere else (unless you have unselectAuto: true in the options).

Relevant documentation:

https://fullcalendar.io/docs/Calendar-unselect

https://fullcalendar.io/docs/unselectAuto

Demo:

document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');
  var calendar = new FullCalendar.Calendar(calendarEl, {
    initialView: 'timeGridWeek',
    editable: true,
    headerToolbar: {
      start: 'prev,next today',
      center: 'title',
      end: 'dayGridMonth,timeGridWeek,timeGridDay'
    },
    selectable: true, //can click to set event
    selectMirror: true, // so it's solid 
    unselectAuto: false, //if you click outside calendar, event doesn't disappear, but if you click inside calendar, event still disappears

    editable: true,
    eventStartEditable: true,
    eventResizableFromStart: true,
    eventDurationEditable: true,
    select: function(selectionInfo) {
      calendar.addEvent({
        title: 'dynamic event',
        start: selectionInfo.start,
        end: selectionInfo.end //need these and not endTime/startTime, otherwise they won't re-render
      });
      calendar.unselect();
    }



  });
  calendar.render();

});
<!DOCTYPE html>
<html>

<head>
  <title>Fullcalendar Demo</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/main.min.css" />
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/main.min.js"></script>
</head>

<body>
  <div id="calendar"></div>
</body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...