Can't get jQuery UI drag helper to change

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago


I'm trying to have a .draggable() object's helper change according to where it is on the screen. To do it, I'm using the helper's set function, with the value being HTML generated from a separate template. By using console.log() statements to see what the helper is, I can see that the HTML has changed appropriately (at least I'm fairly certain), but the helper itself is not changing on-screen. For some context, this is CoffeeScript in a Backbone.js view. Here's my code:

$('#syllabus').droppable({
  scope: "components",
  over: (event, ui) ->
    $('#new_plaintext_button').draggable("option", "helper", $(JST["backbone/templates/components/box"]()))
  out: ->
    $('#new_plaintext_button').draggable("option", "helper", "clone")
})

To clarify, the helper starts out as a clone, and when I hover over the object with the correct scope, it should change to the new HTML object from the template. When I leave the scope, it should return to the clone. Here's the jQuery object for the helper before I change it and after:

[i.fa.fa-3x.fa-file-text-o.ui-draggable.ui-draggable-handle.ui-draggable-dragging, prevObject: jQuery.fn.jQuery.init[1], context: i#new_plaintext_button.fa.fa-3x.fa-file-text-o.ui-draggable.ui-draggable-handle, constructor: function, init: function, selector: ""…]
[div#component_box, prevObject: jQuery.fn.jQuery.init[1], context: document, constructor: function, init: function, selector: ""…]

And as a final note, I've styled this new div in CSS with visible features, so I know it's not the case that my div is just empty so I can't see it. If anyone has any idea why this isn't working, I'd really appreciate it. Thanks.

profilepic.png
manpreet 2 years ago

I've figured out part of my problem. One issue is that in order to change the helper, you have to pass a function as the parameter, not a jQuery object. The other issue is that when the helper is changed, the view isn't updated, so you'll only see the change if you drag the .draggable object a second time. This clarifies things for me, but I still need to figure out how to get the new helper to appear during the original drag. Any advice is appreciated.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.