Search code examples
jqueryjcrop

How to get JCrop to reset selection on deselect?


I am using JCrop for image cropping. It works fine and updates the hidden fields correctly.

The problem I am having is that when the user single clicks the image to clear the selection, the selection area correctly disappears, but the hidden fields do not reset back to 0. Instead, they stay at the same co-ordinates as the previous selection.

I am currently using: onSelect: updateCoords

function updateCoords(c) {
    $('#x1').val(c.x);
    $('#y1').val(c.y);
    $('#width').val(c.w);
    $('#height').val(c.h);
};

But this doesn't get called on deselect.


Solution

  • Found it in the manual, should have checked first! onRelease: resetCoords

    function resetCoords() {
        $('#x1').val("0");
        $('#y1').val("0");
        $('#width').val("0");
        $('#height').val("0");
    };