How to trigger events after editing best_in_place?

On the browse page, I show a list of dates for the occurrence of a periodic event, and statistics calculates the versts of all dates, such as max, min and the average interval between consecutive dates.

I use the best_in_place stone to allow in-place date editing. However, every time the date changes, statistics must be calculated and re-displayed from the server.

How to connect the callback function to the completion of editing best_in_place so that statistics can be displayed again?

This is my Rails code in show.html.erb

<td id="event_date">
  <%= best_in_place @event, :occur_date %>
</td>

which in html is equal

<td id="event_date"> 
    <span class='best_in_place' id='best_in_place_event_132_occur_date' data-url='/events/132' data-object='event' data-attribute='occur_date' data-type='input'>2012-03-23</span>
</td>

I tried the following coffee script code:

jQuery ->
$("#best_in_place_event_*_occur_date").live 'ajax:complete', (evt, data, status, xhr) ->
  alert "a date has changed"

This does not work, nothing happens after I edited the date (event_date).

- , best_in_place?

+3
2

, , , best_in_place ajax: success loadSuccessCallback. , jQuery.

$(".best_in_place").live 'change', (event) ->
  alert "Hello, World!"
+2

:

<td id="event_date">
  <%= best_in_place @event, :occur_date, :classes => 'bip_date' %>
</td>

$('.bip_date').bind("ajax:success", function(){
alert("a date has changed")
});
// or: $('.event_data .best_in_place').bind(...)    

readme:

"ajax: success" .

bind:

$('.best_in_place').bind("ajax:success", function ()
{$(this).closest('tr').effect('highlight'); });

, , 'classes' , .

<%= best_in_place @user, :name, :classes => 'highlight_on_success' %>
<%= best_in_place @user, :mail, :classes => 'bounce_on_success' %>

$('.highlight_on_success').bind("ajax:success", function(){bip_date});
$('.bounce_on_success').bind("ajax:success", function(){$(this).closest('tr').effect('bounce'));});
+1

All Articles