Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to decide whether to accept or reject a jQuery draggable into a droppable
    primarykey
    data
    text
    <p>I'm using jQuery and I have the following problem:</p> <p>In my site I have a chessboard with pieces. Every square is a simple div with the background property to show white or black. Over these squares (inside the divs) I've put an img tag referencing the piece that must be over that square. Something like:</p> <pre><code>&lt;div id="a8" class="square" style="background-image: url('/images/background_white.png')"&gt; &lt;img id="piece_a8" class="piece" src="/images/rook_black.png" /&gt; &lt;/div&gt; </code></pre> <p>I can control the movement of the pieces using jQuery. Every <code>piece</code>-class img is a draggable and every <code>square</code>-class div is a droppable. I already have a server-side function that, given a set of coordinates, returns <strong>"VALID"</strong> if the movement is valid, and <strong>"INVALID"</strong> if otherwise. My idea is, if the server returns "INVALID", the piece must return to its origin square, and if the server returns "VALID", the piece must stay in its new square, deleting every other piece inside the target square.</p> <p>My problem is, I don't know how can I enforce this return value in my jQuery code. I've tried putting functions in the <code>revert</code> property of the draggable, and in the <code>accept</code> and <code>drop</code> functions of the droppable, but I haven't found how to make <code>$.get</code> return false or true.</p> <p>Any help would be really appreciated.</p> <p>Thanks in advance,</p> <p>Léster</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload