Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create nestable draggables in Scriptaculous?

I'm using the Scriptaculous library to slap an appealing UI on an application which helps an enduser build lists. Let's say its for pizza creation.

To fill out an order, you drag a size of pizza from the pizza palette into the orders droppable. Once it is put in there, it gets replaced with a new div which is both draggable (because you can junk it by moving it back to the palette) and droppable (because you can add ingredients to it).

You can then add ingredients from your ingredients palette to any of the pizzas you have sitting in the group of orders.

I've successfully implemented these bits and everything works fine. The stickler: if I attempt to drag and drop the ingredient from a placed pizza, which is properly marked as draggable and which, for good measure, is z-positioned above the pizza, it instead grabs the pizza wholesale. This makes it impossible for me to undo ingredient selections, which is a key feature for this screen.

Any suggestions on how I can get this to do what I want? Ideally I'd like to keep the simple drag-on, drag-off UI as it is worlds more intuitive than what we were using previously. (A multi-stage HTML form... shudder...)

like image 589
Patrick McKenzie Avatar asked Dec 04 '25 20:12

Patrick McKenzie


1 Answers

It turns out, after a few days of banging my heads into various walls, that Scriptaculous will happily nest things by default.

The issue is when your call to draggable_element looks like this

<% draggable_element blah blah blah blah blah blah blah%>

instead of

<%= draggable_element blah blah blah blah blah blah blah %>

D'oh!

like image 132
Patrick McKenzie Avatar answered Dec 06 '25 09:12

Patrick McKenzie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!