Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

javascript - Full Calendar REACT JS - How to disable dragging to inverse-background events

I'm currently creating a booking system utilising Full Calendar with React.

When Dragging a lesson (event), I have all the unavailable booking times appear as grey, but for some reason, I am still able to drag events on those slots, But for the white areas, I am unable to drag.

How would I reverse this?

Image of my timetable

Some of my code:

My array of available lessons:

let avail = [
{
  groupId: "lesson-available",
  start: "2021-01-13T10:00:00",
  end: "2021-01-13T16:00:00",
  color: "#ccc",
  display: "inverse-background",
},
{
  groupId: "lesson-available",
  start: "2021-01-14T16:00:00",
  end: "2021-01-14T19:00:00",
  color: "#ccc",
  display: "inverse-background",
},
{
  groupId: "lesson-available",
  start: "2021-01-15T16:00:00",
  end: "2021-01-15T19:00:00",
  display: "inverse-background",
  color: "#ccc",
},
{
  groupId: "lesson-available",
  start: "2021-01-16T16:00:00",
  end: "2021-01-17T19:00:00",
  display: "inverse-background",
  color: "#ccc",
},
];


-------------------------------------------------------

<FullCalendar
        plugins={[dayGridPlugin, timeGridPlugin, interactionPlugin]}
        headerToolbar={{
          left: "prev,next today",
          center: "title",
          right: "dayGridMonth,timeGridWeek,timeGridDay",
        }}
        initialView="timeGridWeek"
        editable={true}
        eventColor="#6DCBCA"
        selectable={false} // Allows a user to highlight multiple days or timeslots by clicking and dragging.
        selectMirror={true}
        dayMaxEvents={true}
        weekends={true}
        events={currentEvents}
        select={handleDateSelect}
        eventContent={renderEventContent}
        eventClick={handleEventClick}
        eventDrop={handleEventDrop}
        eventDragStart={handleEventDragStart}
        eventDragStop={handleEventDragStop}
        eventOverlap={false}
      />
question from:https://stackoverflow.com/questions/65662260/full-calendar-react-js-how-to-disable-dragging-to-inverse-background-events

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

1 Reply

0 votes
by (71.8m points)

The bit which isn't coloured #ccc is the area where the event is located. So you can't drag onto the event. That's what you told the code to do with the eventOverlap setting - i.e. don't allow dragging onto existing events. The fact that you also told it to invert the background colour is irrelevant - that's just a visual detail.

What you can do instead of eventOverlap is use eventConstraint - it allows you to specify a groupId indicating events over which events may be dropped. It then ensures they cannot be dropped anywhere else. Since you've already defined a groupId for your background events, this becomes trivial:

eventConstraint: "lesson-available"

(In the React Component syntax, this would be eventOverlap="lesson-available" I think.)

Documentation: https://fullcalendar.io/docs/eventConstraint

Demo: https://codepen.io/ADyson82/pen/mdrGqoz


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...