I am making use of the jQuery UI sortable interaction and Jeditable. The idea being that a user can reorder elements and affect the content of those elements. What I am running into is that the onblur event
that I have Jeditable setup to listen for is being swallowed by the jQuery sortable listener.
A user can click on a Jeditable element and that element becomes editable, but when they click away if they click on an li
that is sortable the onblur event is ignored. The event is not ignored if they click outside the li
. How can I make Jeditable aware of the blur event when they click inside an li
?
Here's a jsFiddle illustrating the problem
HTML Markup
<ul class="elementlist">
<li id="elementSk_10">
<span class="editable-element" id="10">TEXT!</span>
</li>
<li id="elementSk_33">
<span class="editable-element" id="33">Some text</span>
</li>
</ul>
Jeditable
$('.editable-element').editable('http://jsfiddle.net/echo/jsonp/', {
onblur: 'submit',
width: 250,
indicator: 'Saving...'
});
jQuery UI Sortable
$(".elementlist").sortable({
update: function(event, ui) {
var elementSerialized = $(this).sortable('serialize');
$.post('http://jsfiddle.net/echo/jsonp/', {
elementSk: $(this).sortable('serialize')
});
}
});
Edit: In an attempt to clarify what's going on let me give a step by step walkthrough accompanied by screenshots.
- Click
Some Text
- Click on
li
containingTEXT!
- Release click on
TEXT!
At this point I haven't reordered anything. Clicking on the li
and releasing hasn't triggered the onblur
for Jeditable. I would like the simple act of clicking away to trigger the onblur. If I do not wire up sortable this is how it works. I have to believe somehow the click on the li
is being swallowed by sortable.
Here's another example with reordering but still no onblur
.
- Click
Some Text
- Click on
li
containingTEXT!
- Move
TEXT!
belowSome Text
- Release hold on
TEXT!
After reordering the elements and releasing the li
containing TEXT!
the onblur
isn't captured. The elements are in a new order but the Some Text
is still in an editable state.
All of that said here is what I would expect to happen:
Clicking on anything outside of a field currently being edited should cause the onblur
of Jeditable to fire. Which is exactly what happens if jQuery sortable isn't wired up. When jQuery sortable is wired up to cause the onblur
behavior I have to click outside of the sortable list elements.