I'm using best_in_place to do in-page editing of a table of data in a ruby-on-rails app. The in-place editing works, but I have a corner case that fails. A pair of items in the row (device_name, generic_name) must be unique. If they are not unique, the server-side code passes back a set of names with a changed generic_name to make the pair unique. I use the following coffeescript to update the display.
jQuery ->
$('.best_in_place[data-bip-object="full_dpoint"]').bind(
"ajax:success", (event, d) ->▫
return if ! d?
data = JSON.parse(d)
if ! data.dpoint?
return
else
item_to_edit = "#best_in_place_full_dpoint_" + data.dpoint.dpoint_id + "_generic_name"
$(item_to_edit).text(data.dpoint.generic_name)
)
This code works (IE it properly updates the page with the server-supplied new generic name) , but if I then click back in the 'generic_name' field, (to go into edit mode), the default edit text changes back to what it was at the very beginning (page download time). I have experimented with setting many different page elements to the new generic name, including all of the following:
$(item_to_edit).attr('data-bip-original-content', data.dpoint.generic_name)
$(item_to_edit).attr('data-bip-value', data.dpoint.generic_name)
$(item_to_edit).attr('original-value', data.dpoint.generic_name)
$(item_to_edit).attr('bipValue', data.dpoint.generic_name)
$(item_to_edit).attr('bipvalue', data.dpoint.generic_name)
All to no avail. I have poked around in the dom trying to find where the original value might be stored, but haven't found anything other than these.
Any ideas?
TIA.
Leonard