JQuery edit plugin that lets you trigger editing from another element

I am currently using Jeditable for in-place editing functionality. Jeditable has a few useful options, but (as far as I know) it prevents editing from being triggered other than clicking the appropriate element.

Ie let my element have id comment

. With Jeditable, the only way to start editing is to click comment

. I would like to add a little text next to comment

(for example, "Click to edit comment") that, when clicked, turns comment

into an editable text box (and customize the Save and Cancel buttons, etc.).

+2


source to share


3 answers


Okay, I hacked the case. In this blog post, the author writes

Now you can use any custom event to trigger Jeditable.

$(".editable").editable("http://www.example.com/save.php", { 
   event     : "make_editable" 
});

      



So I did this and then did:

  $("#id-for-text").click(function() {
    $("#comment").trigger('make_editable');
  });

      

+5


source


Check out jQuery trigger .

Use code:



$('#id-for-text').click(function(){
  $('#comment').trigger('click');
});

      

+1


source


Based on your comments above, you can do this:

var editFn = (function(){ return $('#comment').click; })();
$('#id-for-text').click(editFn);
$('#comment').unbind('click');

      

This tells the label that the click event should match the click event and then unbinds the event in the comment.

Not sure if unbind will destroy the link to editFn, hence enable closure.

+1


source







All Articles