The dragend event in JavaScript is triggered right after the dragstart event

I'm facing a critical bug that's causing significant issues for me.

In my Vue project, I have developed a form generator component. It consists of a draggable area with user-friendly draggable items such as short answer, long answer, numeric answer, radio/checkbox answer, and more.

The drag-and-drop functionality allows me to place these items in a drop zone where they are then added to an object to create a preview of the form.

Everything seems to be working smoothly, except for one major issue... Occasionally, when I initiate a drag action and the dragstart event is triggered (I've confirmed this with console logs), the dragend event fires almost immediately even though I'm still holding down the mouse button.

This problem occurs randomly and doesn't seem related to any specific type of field being dragged from the draggable area. While there was a known Chrome bug related to this issue, it had supposedly been resolved (or so I believe).

I am currently using Chrome version: Version 78.0.3904.108 (Official Build) (64-bit), and I suspect similar issues may have occurred with previous versions.

Below, I'll provide some pseudo-code snippets to illustrate the implementation:

DraggableArea.vue

<template lang='pug'>
  #draggable-area
    ul
      draggable-item(
        v-for='draggableField in draggableFields'
        :fieldInfoToBeDropped='draggableField.fieldInfoToBeDropped'
      )

</template>

DraggableItem.vue

<template lang='pug'>
  li(
    draggable='true'
    @dragstart.stop='handleDragstart'
    @dragend.stop='handleDragend'
    @drop.stop='handleDrop
</template>

export default {
  ...

  methods: {
    handleDragstart(e) {
      const fieldInfoToBeDropped = this.fieldInfoToBeDropped // contains information for drop zone handling
      
      console.log('DraggableItem, handleDragstart event:', e)
      setTimeout(() => { this.$el.classList.add('drag') }, 10)
      e.dataTransfer.clearData()
      const fieldObjectStr = JSON.stringify(fieldInfoToBeDropped)
      e.dataTransfer.setData('fieldObject', fieldObjectStr)
      
    },

    handleDragend(e) {
      console.log('DraggableItem: dragend fires')
      this.$el.classList.remove('drag')
      e.dataTransfer.clearData()
    },

    handleDrop(e) {
      this.handleDragend(e)
    }

  }

An example of fieldInfoToBeDropped structure:

{
 componentType:"text",
 name:"",
 description:"",
 iconName:"text",
 id:"field_1575448385646rgzh6hhh6",
 mandatory:true
}

I haven't tested the functionality in other browsers yet, but so far, the issue has only arisen in Chrome.

Thank you!

Answer №1

This was figured out by me.

During the dragging of an item, I purposely conceal certain content causing the window height to decrease from its original size. This in turn triggers the appearance and disappearance of the scroll bar, leading to movement of my cursor and activation of the drop event.

This peculiar behavior is exclusive to Google Chrome

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unexpected behavior involving the onchange event, input validation, and the enter key

One challenge I encountered was implementing validation for a date input field in a form. The requirement was to only allow dates starting from today up to a maximum of 3 years in the future. If a valid date is entered, a modal should appear; otherwise, an ...

The form submission button fails to function when the onsubmit function returns false

When submitting, I check two fields. If one of the two fields is checked, then I return true; otherwise, I return false. The issue I'm facing is that even when I check one of the checkboxes, the submit button does not seem to work (I use console.log() ...

What could be the reason that data-bs-placement="right" is not functioning as expected?

I am facing an issue with the popover functionality in my project. No matter what value I set for data-bs-placement attribute, it does not display correctly. Can you help me understand why this is happening? <!DOCTYPE html> <html lang="en ...

Preventing Duplicate Content in jQuery.ajax when Posting Data on the Same Page

Issue 1: I am experiencing content overlap after sending data back to the same page using jQuery.ajax(). This is necessary as I need to transfer JavaScript values to PHP. How can I modify my code to prevent the content from duplicating before and after pos ...

Unique title: "Implementing Unique Event Handlers with VueJS Components"

My VueJS and Buefy project begins with two distinct click actions: Click on the Cyan area -> redirects to another page (Action 1) Click on the Magenta area -> shows a dropdown menu (Action 2) https://i.stack.imgur.com/AVLOS.png However, when clic ...

Tips for saving and accessing the value of an md-select ng-model in an AngularJS dialog?

Currently, I am utilizing a template to populate an md-dialog box: The procedure for displaying the dialog: $scope.showDialog = function(element) { var parentEl = angular.element(document.body); $mdDialog.show({ template: element, scope: $scope, pr ...

Angular Navigation alters the view

I want to navigate to a different page using Angular routing, but for some reason it's not working. Instead of moving to the designated Payment Component page, the content is staying on my Main Component. Why is this happening? app.routing.module.ts ...

Unable to retrieve chosen rows using Angular UI Grid

My scenario involves managing two grids with selectable rows. I aim to retrieve the data from the selected rows and store it in a separate object to send it to a backend service. Here is the relevant code snippet: angular.module('gridPanel',[&ap ...

What could be causing the error "Cannot read the state property of undefined in react-native?"

I really need some assistance. I am attempting to create a JSON object called users in my state properties to test the functionality of my authentication system. However, when I tried to access it, I encountered the error "Cannot read property 'state& ...

Duplicating labels with JavaScript

I need assistance with copying HTML to my clipboard. The issue I am encountering is that when I try to copy the button inside the tagHolder, it ends up copying <span style="font-family: Arial; font-size: 13.3333px; text-align: center; background-color: ...

Tips for successfully passing props to a component while utilizing the Quasar dialog plugin

As per the information provided in quasar documentation, it mentions that the custom component utilized with the dialog plugin is capable of having props. However, I am unable to figure out the method for passing these props to the component through thi ...

Is there an easy method to verify if the local storage is devoid of any data?

Query is named aptly; seeking to verify in a conditional statement. ...

I encounter obstacles when trying to execute various tasks through npm, such as downloading packages

Currently, I am facing an issue while trying to set up backend development using node.js on my personal computer. The problem lies with the npm command as it is not functioning correctly. Despite successfully installing a file without any errors, I am unab ...

Having difficulties persisting information from freshly generated input fields with the "Add" button to the database

Currently, the issue lies with the database only accepting data from the first input field in PHP. <form class = "spendings" method ="POST" action="InsertToDatabase.php"> <div id="numbering">ITEM 1: </div> <div class="entry"> ...

Alter the navigation but keep the URL intact without modifying the view

I have an Angular project that includes a login component. The login component is located in the directory app/main/login. I am trying to navigate to the login component from app.component.html using a button. Below is the code snippet from my app-routi ...

Revamp your array elements with MongoDB - Substring replacement

Having some difficulty replacing a substring within various documents. Below is an example of one such document: { "images" : [ { "url" : "https://example/1234" }, { "url" : "https://example/afaef" }, { "url" : ...

The most effective method for acquiring an object through inheritance

I'm seeking advice on the best practice for adding behavior to an object received as a JSON object. I have REST services that allow me to define a sort of state machine. The API defines a /sessions resources. When creating a session via POST /sessio ...

The output of new Date() varies between app.js and ejs

app.get("/test",function(req,res){ var d = new Date(); res.send(d); }); When I access mydomain/test, it displays the output "2019-03-19T04:50:47.710Z" which is in UTC. app.get("/testejs",function(req,res){ res.render("testejs");}); Below is the content ...

Loading Datatables using PHP to send JSON data

I seem to be facing some difficulty in troubleshooting the issue within my code. Currently, I am working on a search script and would like to display the results using Datatables. I have a search form that sends data to my PHP file which then returns a JS ...

The type 'Readonly<Ref<Readonly<any>>>' does not have the property 'forEach' available

Having an issue with state management in Vue3 (Pinia) using the Composition API. I successfully retrieved an array called countryCodes and now I want to copy all items from this array into another array called countries defined in the state. However, whe ...