Identifying Dragged Items and Drop Locations in AngularJS Drag and Drop Feature

We are in the process of developing our initial AngularJS application. One element of the website involves allowing users to drag individuals into specific groups. Similar to Google+ circles, a user can select another user and move them into a circle to include them in that group.

To achieve this functionality, we recognize the need to create a directive. Here is what we have drafted so far:

var DragDrop = angular.module('ajs.Directive.dragDrop', []);

DragDrop.directive('myDrag', function () {
return {

    link: function(scope, elt, attrs) 
    {      
       // scope.obj.outer = "Updated on link";            
        elt.draggable({revert:"invalid"});            
        elt.droppable({        
            //accept: function( d ) { return true; },                
            drop: function (event, ui) {
                return scope.$apply(function () {
                    alert("hello")
                    scope.inner = 'Dropped';                        
                   // scope.obj.outer = 'Updated on drop';                    
                });                
            }            
        });          
    }        
}
});

Our current setup allows us to drag contacts across the screen. Nonetheless, we are facing challenges when it comes to determining the ID of the dragged element and where it has been dropped.

In addition, following the example mentioned earlier, once an item is dragged, we want it to return to its original position rather than staying in the new location.

We attempted to use revert:"invalid" within the elt.droppable section, but it did not produce the desired outcome.

It is worth noting that we cannot utilize jQuery due to these elements being part of an ng-repeat loop. Consequently, it seems like creating a directive is the most suitable solution for this scenario.

Answer №1

Take a look at this awesome resource: It could be just what you need without having to start from scratch. You have access to the source code, allowing for potential enhancements.

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

Guide on navigating to a different page following a successful Google Sign In within React18

I'm facing an issue with redirection after signing in with Google on my React 18 project. Despite successfully logging in, the page does not redirect as expected. Below is a snippet of my Login.jsx file where the Google login functionality is implemen ...

Display an indicator during the file upload process

Is it possible to display an upload indicator using ng-file-upload while the file is being uploaded? I have checked the documentation but couldn't find a solution. Perhaps there is another way to achieve this? ...

Issues with appending new rows using JavaScript

I'm facing an issue with adding rows to the table using this code and I can't seem to find a solution. function add() { document.getElementById("popup").style.display = "block"; document.getElementById("add").addEventListener("click", func ...

Turn off the validation of individual JavaScript errors in Eclipse

Currently, I am exploring the use of Eclipse for JavaScript within the "Eclipse IDE for Java EE Developers" package. In my project, there is a heavy reliance on Bluebird, a promises implementation, resulting in several lines like: somePromise.catch(funct ...

Filtering arrays using Vue.js

I have developed a sample e-commerce website to showcase various products to potential customers. The website boasts features like filters, search functionality, and sorting options to enhance the user experience. However, I've encountered an issue sp ...

I continue to encounter an error every time I attempt to place an HTML nested div on a separate line

When I structure the HTML like this, I don't encounter any errors: <div class="game-card"><div class="flipped"></div></div> However, if I format it differently, I receive an error message saying - Cannot set property 'vi ...

"Effortlessly Engage Users with Rails and AJAX Comment Posting

Running a simple blog app dedicated to video game reviews, I encountered an issue with AJAX. As a self-taught student developer, I'm facing a challenge where posting comments on review pages triggers a full page refresh instead of dynamically updating ...

Tips for closing 2 models in a React application

Currently, I am working on a project using ReactJs. One of the functionalities I am implementing is generating a user's gallery when the user clicks on their avatar. To achieve this, I am utilizing the react-grid-gallery package along with semantic ui ...

If the ID matches a value in the list, assign a class to the div

Hello, I am looking for assistance on how to add a class to a div if its id matches a value from a predetermined list: list = ["a1", "a2", "a3"] <div id="a1"></div> <div id="b1"></div> <div id="c1"></div> <div id=" ...

Request not reaching web method during AJAX invocation

In my AngularJS directive, I am calling a function that makes an AJAX POST call to a C# web method. app.directive("fileread", [function () { return { link: function ($scope, $elm, $attrs) { $elm.on('change', function (changeEvent) { var dat ...

Developing maintenance logic in Angular to control subsequent API requests

In our Angular 9 application, we have various components, some of which have parent-child relationships while others are independent. We begin by making an initial API call that returns a true or false flag value. Depending on this value, we decide whether ...

The object3d.translateZ function in Three.js is resulting in unexpected NaN values for all position properties

I'm encountering an issue where the use of translate[X|Y|Z] on my object results in its position becoming distorted and only displaying NaN values. Using Three.js r70 The relative position differs from the absolute position: Snippet from my code i ...

directive provider not found

I've been attempting to integrate a directive into my project. Here is the code for the directive: "use strict"; var kf = angular.module('kingaFrontend'); kf.directive('FlashMessages', function() { return { restrict: &apos ...

Error: Unexpected token 'undefined' encountered, which is not recognized as a primary expression. This error occurs at column null within the expression [xx], beginning at [xx%]

When using my sorting function, it does not work properly if the column name contains a %. For instance, when columnName == "calldrop", my function works as expected. However, when columnName == "calldrop%", I encounter an error message that says: Syntax ...

The directive code takes precedence over the controller code and is executed first

A custom directive has been implemented and is utilized as shown below: <div car-form car="car" on-submit="createCar(car)"></div> This directive is used on both the new and edit pages, each with its own controller. The EditCarController retri ...

Verify if an item possesses a certain attribute

Is there a way to verify the existence of a specific property within an object using AngularJS? ...

Selecting random numbers in React.js

I am working on creating a Netflix Clone and I want to change the banner image every time the page refreshes. I have integrated movie details from TMDb and have an array containing these details. My goal is to select a random number between 0 and 19 and us ...

Error message: Unable to destructure the 'top' property of 'el.position(...)' due to its undefined state in WordPress using jQuery

I encountered an error on a Wordpress site that I am not very familiar with. The error message that appeared in the console is as follows: jquery-3.5.1.min.js:formatted:1504 Uncaught TypeError: Cannot destructure property 'top' of 'el.positi ...

Is it possible to revert an image back to its original state after it has been altered on hover

I am currently experimenting with jQuery to create an image hover effect where hovering over one image changes the other. I've managed to accomplish that part successfully. However, I'm struggling with how to make the original image revert back w ...

Accessing the 'comment' property within the .then() function is not possible if it is undefined

Why does obj[i] become undefined inside the .then() function? obj = [{'id': 1, 'name': 'john', 'age': '22', 'group': 'grA'}, {'id': 2, 'name': 'mike', &apo ...