Skip to main content

Search and Top Navigation

#3491 closed bug (wontfix)

Opened October 21, 2008 05:51PM UTC

Closed November 03, 2008 01:51PM UTC

Last modified September 23, 2009 09:29PM UTC

Sortables:temp. inline styles not removed prior to stop callback fcn

Reported by: Firehed Owned by: paul
Priority: minor Milestone: 1.7
Component: ui.sortable Version: 1.6rc2
Keywords: Cc:
Blocked by: Blocking:
Description

I have a callback function on my sortables stop that sends the contents of the sortable element off for processing via AJAX. When I updated my UI library to 1.6RC2 I started seeing the temporary inline styles also sent along in the AJAX request, which were not previously present.

Sample code to duplicate:

$(document).ready(function(){
	$("#builder").sortable{
		stop: saveSortData
	});
});

function saveSortData() {
	target = document.getElementById('builder');
	var xhtml = "";
	xhtml = parsenode(target, true); 
//custom function that gets innerHTML of an element retaining proper XHMTL tags
//was submitted as a separate bug report on the main jQuery library

	$.post('ajax_builder_process.php', {
		formHTML: xhtml,
		formID: $("#formID").val()
	});
} //fcn sendSortData

Anyways, my resolution to the problem was to add the following to the top of my sendSortData() function:

$("#builder").children().removeAttr('style');

That strips all of the inline styles that are applied while you're actually doing the sorting: style="position: static; top: auto; left: auto; clear: none; z-index: auto; " (that's what it looks like when you stop sorting anyways, and was sent in the AJAX request until I added the above line).

As a proposed solution, something similar to the line of code above should be called prior to the stop callback function being run on sortables, if not sooner. May also apply to draggables; I haven't checked.

Just to be totally clear, without the above fix, the AJAX page gets this:

<div class="formElement" 
style="position: static; top: auto; left: auto; clear: none; z-index: auto; ">
	sample contents...
</div>

instead of this:

<div class="formElement">
	sample contents...
</div>

This was introduced somewhere in the creation of the current 1.6RC2, as this behavior didn't exist prior to updating. I don't know exactly which version of sortables I had been previously using unfortunately - I think 1.5.2.

Thanks for looking into this!

Eric

Attachments (0)
Change History (1)

Changed November 03, 2008 01:51PM UTC by paul comment:1

resolution: → wontfix
status: newclosed

Hi there, this is actually not a bug, let me explain it to you:

In 1.6, we refactored sortable to be able to use the original element as mouse helper, and since it needs to be positioned during the drag, we will reset the styles at the end. However, if you didn't expliticely set a style for position, for example, jQuery will still return "static", as it's using the inline style, so there's no good way to fix this.

However, there's a mode that might work better for you: set the "helper" option to "clone", and you'll get the behaviour of 1.5.2, which should do the magic for you.