Skip to content

Instantly share code, notes, and snippets.

@brianmfear
Created February 20, 2017 16:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianmfear/fb13ac4781c79fad6495ef7dc1676f4f to your computer and use it in GitHub Desktop.
Save brianmfear/fb13ac4781c79fad6495ef7dc1676f4f to your computer and use it in GitHub Desktop.
Drag and Drop in Lightning (simple demo)
<aura:application >
<aura:attribute name="values"
type="String[]"
access="private" />
<aura:attribute name="dragid"
type="Integer"
access="private" />
<aura:handler name="init"
value="{!this}"
action="{!c.doInit}" />
<div class="droparea"
ondragover="{!c.cancel}"
ondragenter="{!c.cancel}"
ondrop="{!c.drop}">
<aura:iteration items="{!v.values}"
indexVar="index"
var="value">
<div class="row"
draggable="true"
ondragstart="{!c.dragstart}"
data-drag-id="{!index}">
{!value}
</div>
</aura:iteration>
</div>
</aura:application>
.THIS.droparea{
border: 1px solid black;
position: relative;
margin: 3px;
}
.THIS.droparea .row {
position: relative;
border: 1px solid red;
padding: 3px;
margin: 3px;
}
({
doInit: function(component, event, helper) {
var values = "a b c d e".split(' ');
component.set("v.values", values);
},
dragstart: function(component, event, helper) {
component.set("v.dragid", event.target.dataset.dragId);
},
drop: function(component, event, helper) {
var dragId = component.get("v.dragid"),
values = component.get("v.values"),
temp;
temp = values[dragId];
values[dragId] = values[event.target.dataset.dragId];
values[event.target.dataset.dragId] = temp;
component.set("v.values", values);
event.preventDefault();
},
cancel: function(component, event, helper) {
event.preventDefault();
}
})
@dineshsm
Copy link

dineshsm commented Aug 17, 2017

screenshot 2

After two or three drag and drops the div becomes empty. values in it get disappeared . @brianmfear Can you help me with this

@capcoldy
Copy link

dragging not working on firefox. how it can work on firefox.

@srikanthyeturu
Copy link

screenshot 2

After two or three drag and drops the div becomes empty. values in it get disappeared . @brianmfear Can you help me with this

Hi Did you Find the Answer for this

@brianmfear
Copy link
Author

screenshot 2
After two or three drag and drops the div becomes empty. values in it get disappeared . @brianmfear Can you help me with this

Hi Did you Find the Answer for this

@srikanthyeturu,

Hi, I'm sorry I missed the original message, but I'll take a look at this. Thanks for bringing it to my attention. I tested this only in Chrome, but I'll give it a try on Firefox. Can you please provide a precise description of what you did to arrive at this situation?

@srikanthyeturu
Copy link

srikanthyeturu commented May 25, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment