The FOS - Drag and Drop dynamic action plug-in makes it possible to drag & drop elements inside a region. This could be a Cards region, a Badge list or basically everything that has a group of elements.
On every change of the order of items an event is fired passing the necessary change information accessible via "this.data" within your dynamic action handler. Additionally you can execute PL/SQL code to do an update of your database tables or execute some additional Javascript code.
The plug-in is built around Shopify's Draggable library (https://github.com/Shopify/draggable).
Thanks to the plug-in's structure and to the simple interface it comes with, it is very easy to add the functionality to any component. The only thing you have to take care of is that the draggable DOM elements inside the component must be uniquely identifiable. If there is no unique ID, the plugin can't inform the dynamic action of the correct sequence. There are two ways to pass the identifiers: either set a data-id attribute on the draggable elements (this would be the default behavior) or utilize the config.dataIdFn property in the JavaScript Initialization Code. If you define this function, the first and only parameter it would receive is the dragged DOM element. You should return a unique ID from this function for every element. Here is an example how the DOM ID could be used instead of the (default) data-id attribute:
function (config) {
config.dataIdFn = function (el) { return el.id };
}
The presence of the data-id attribute depends not only on the Component but on the selected Template as well, e.g. the Menu Popup Template on a List component has a declarative Data ID attribute, but the Badge does not. While in the first case, you can just pass the value to the attribute and that's it; in the latter you must add it by yourself; in the examples below we show you a few very simple workarounds how to achieve it.