Search code examples
javascriptjqueryjquery-pluginsjeditablejquery-events

jQuery jeditable trigger on click


I need to use inline edit in my application. For this purpose I am using the Jeditable plugin for jQuery.

I want to trigger editable mode for an element only when I click on it. This is my code which doesn't work:

var tet = "";
$(".edit-client").click(function(event) {
    tet = "#"+event.target.id;
    //alert(tet);
});

$(tet).editable("/bestcredit/admin.php/request/editClient", {
    submitdata : function (value,settings){
                    return {"Client[id]":'.$model->client->id.' };
                },

    //indicator : "Saving...",
    //tooltip   : "Click to edit...",
    submit   : "OK",
    name : "Client["+tet.substr("1")+"]"
    //alert(1);
 }); 

How can I add this functionality?


Solution

  • There are many ways to do it and it all depends on your HTML, but for example if you have following HTML:

    <div class="edit" id="unique_id">Editable text</div> 
    <a href="#" class="edit_trigger">Edit me!!</a>
    

    Then you can use following JavaScript:

    /* Bind Jeditable instances to "edit" event. */
    $(".edit").editable("http://www.example.com/save.php", {
        event     : "edit"
    });
    /* Find and trigger "edit" event on correct Jeditable instance. */
    $(".edit_trigger").bind("click", function() {
        $(this).prev().trigger("edit");
    });