Utilizing the dnd library to incorporate drag and drop functionality

I've encountered an issue with the code snippet below. Although I am able to drag elements, I am unable to drop them. How can I trigger the dropFunction when a drop occurs?

Drag code:
            <div>
            <a class="button" ng-class="{editing: mode == modes.edit_rows}" ng-repeat="col in definition.columns" ng-click="editColumn($index)"
                dnd-type="'columnPills'" 
                dnd-draggable="event"
                dnd-effect-allowed="copy"
                dnd-copied=""
                dnd-effect-allowed="move"
                dnd-moved="moveAndDeletePills(definition.rows,$index)">{{name.toString()}}</a></div>

Drop code:
            <div dnd-allowed-types="'columnPills'"
            dnd-drop="dropFunction(event, index, item, external, type, definition)"
            dnd-dragover="true"
            dnd-droppable="true">
            </div>

I have attempted calling the drop function dropFunction() without any arguments, but unfortunately, the function does not execute.

Answer №1

Are you sending back the 'item' in the callback function?

  $scope.dropCallback = function(event, index, item, external, type, allowedType) {
    if (external) {
        ...
        return false;
    }
    return item;
  };

Refer to the Documentation below, specifically where it states "it must return the object that will be inserted"

"dnd-drop Optional expression that is called when an element is dropped over the list. If the expression is used, it should return the object to be added to the list. If it returns false, the drop will be stopped and the event is propagated."

https://github.com/marceljuenemann/angular-drag-and-drop-lists

Answer №2

Appreciations to @sjm for the valuable input! However, it is worth noting that in addition to implementing the callback, we must ensure the usage of dnd-list in the drop code because the dnd library specifically functions with a list.

Furthermore, it is crucial to pass the list as an argument and append the new dropped object to the list.

Following thorough research and testing, I am delighted to present the accurate code below.

Drag Code:
                 <div>
                 <li class="button" ng-class="{editing: mode == modes.edit_rows}" ng-repeat="col in definition.columns" ng-click="editColumn($index)"
                 dnd-type="'col'" 
                 dnd-draggable="col"
                 dnd-effect-allowed="move"
                 dnd-moved="moveAndDeletePills(definition.rows,$index)">{{name.toString()}}</li>               
                 </div>


Drop Code:
        <div dnd-allowed-types="'col'"
        dnd-list="definition.rows"
        dnd-drop="dropFunction(event, index, item, external, type, definition)"
        dnd-dragover="true"
        dnd-droppable="true">

        <li class="button" ng-repeat="row in definition.rows" ng-click="editRow($index)"</li>
        </div>

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

Executing a JavaScript function when an HTML page is loaded within an OBJECT Tag

I have a situation where I am loading an HTML page inside an object tag. Since the iPad does not support iFrames, I decided to use the object tag to load external HTML pages into a container. Everything is working well so far, but now I want to be able t ...

Ensuring strictNullChecks in Typescript is crucial when passing values between functions

When using the --strictNullChecks flag in TypeScript, there seems to be an issue with inferring that an optional property is not undefined when the check occurs in a separate function. (Please refer to the example provided, as articulating this clearly is ...

What is the process for generating an array of arrays in a React component?

I'm currently working on developing a word-guessing game similar to Wordle using React. The interesting twist in this game is that players have the ability to choose both the number of attempts allowed and the length of the word they are trying to gue ...

Manipulating global state properties within a reducer function in React: How to do it efficiently

I am looking to implement a single loader (backdrop and spinner) within my app component that can be displayed based on the value of a property in the Redux state called showLoader. This loader should be accessible throughout my entire React application. T ...

Issue with AngularJS directive failing to trigger on click event

I have adapted the JQuery code from my client app design into an AngularJS directive as shown below, but unfortunately the on-click event is not working properly (no action when clicking on the boxes). Could someone please help me identify what I am doing ...

Navigating with Angular 1.5 Component router in conjunction with Express.js

I'm currently working on an Express application and I am trying to capture all routes to redirect users to /public/app/index.html: app.all('/*', function (req, res, next) { // Let's just serve the index.html for other files to enab ...

Possible rephrased version: "Encountering a Jquery clash

It appears that the issue causing my problem may be a Jquery conflict. Please correct me if I am wrong after reviewing the information below. I am new to Jquery and attempting to add a dropdown plugin to a website. The attempt is successful, but an existi ...

What is the best way to submit updated data from an Angular form?

Currently, I have a situation where multiple forms are connected to a backend service for storing data. My query is whether there exists a typical angular method to identify which properties of the model have been altered and only send those in the POST r ...

Accessing an array outside of an Ajax call that was initiated within a success callback

I have a CSV parsing function written in JavaScript that extracts movie names from a CSV file using an Ajax call within a loop. movies = new Array(); for (var i = 1; i < allData.length; i++) { var mName = allData[i][0]; var mPath = allData[i ...

Using jQuery to create a dynamically moving div that forms an endless wall

In order to create a continuous wall that pulls text from a database and displays it, I've developed the following code: $(function() { var x = 0; var y = 100.0; var z=0; setInterval(function() { x -= 0.1; y -= 0.1; ...

Troubleshooting issues with data parsing in an Angular typeahead module

Utilizing the AngularJS Bootstrap typeahead module, I am attempting to showcase data from an array of objects. Despite receiving data from my API call, I keep encountering the following error: TypeError: Cannot read property 'length' of undefine ...

Establishing a default v-on event for a Vue component

Within my custom 'text-input' components, I include some default markup and an 'input' element. An effective method for passing the value of the 'text-input' to its parent is by emitting an event when the value changes. To h ...

Why won't the props pass down to the child component?

I am facing an issue while trying to pass two values as props from a React component "App" to its child "Todo". The values being passed are "title" and "completed" from a json placeholder API. The JSON object is correct and has been verified. The problem ...

Issue with highcharts and vue.js: creating a unique chart for displaying measurements

Currently, I am integrating Highcharts and Vue.js simultaneously while incorporating multiple charts on my webpage. As of now, I have successfully displayed data on all the charts without encountering any issues. However, my goal is to assign a special tit ...

Is it possible to dynamically update the currency symbol in an AngularJS filter?

Query Background: I have a dropdown menu with 4 country options: UK (United Kingdom), US (United States), FR (France), GER (Germany). Depending on the selected option, I need to filter a price in my Controller's Scope object to display the correct cu ...

Reconfigure an ancestral item into a designated key

I have a single object with an array of roles inside, and I need to transform the roles into an array of objects. See example below: Current Object: displayConfiguration: { widgetList: { widgetName: 'widget title', entityType: 'As ...

What is the process for deploying a next.js application with a custom express backend to a VPS or Heroku platform?

Does anyone have advice on deploying a next.js application with a custom express backend to either a VPS or Heroku? ...

JavaScript (Create a button that toggles the visibility of an element)

I have implemented a hamburger menu that transforms into an x when clicked. I am looking to modify it so that clicking on the hamburger opens the menu, and clicking on the x closes the menu. Below is the code I have been working with: <!DOCTYPE html&g ...

Issue with Jquery animation

I'm facing a strange issue. I've created a jQuery function that animates the result bars of a poll. function displayResults() { $(".q_answers1 div").each(function(){ var percentage = $(this).next().text(); $(this).css({widt ...

The ng-grid in Angular fails to update when changes are made from a modal dialog

There is a form on the page that consists of textboxes and a submit button. Upon entering values in the textboxes and clicking the submit button, a grid is displayed. The grid contains multiple columns with a delete button at the end of each row. Clicking ...