Search code examples
javascriptjqueryx-editable

Changing the value of x-editable


I have a few hyperlinks that I use with x-editable. They basically represent the size of a resizable div. Now when I resize the div, I'm setting the text of the <a> elements to display the new size. The problem is when I then click the hyperlinks and x-editable comes in the initial value of the input is not changed according to the new text value of the corresponding <a> element.

So if the initial div size is 400x400 and I resize it to 600x400 then when I click to edit the width, the initial textbox value is still 400.

function updateDivSize(div) //this is called whenever the div is being resized
{
    //$(context).find(".width-editable").editable('setValue', $(div).width());
    //$(context).find(".height-editable").editable('setValue', $(div).height());
    $(context).find(".width-editable").text($(div).width());
    $(context).find(".height-editable").text($(div).height());
}

Now if I call .editable() on the a elements again each time it works fine, but the problem is that I lose all of the other settings of the x-editable, which I'd like to keep. Is there any way I can do this without calling .editable() again with all of the other settings every time I resize the divs ?

JSFiddle


Solution

  • You need to reload the X-editable function, but before you can du that you need to destroy it like this:

    $(".width-editable").editable('destroy');
    $(".height-editable").editable('destroy');
    

    I have edited your JSFiddel, please see the new one here: http://jsfiddle.net/xBB5x/9957/

    Hope it helps!