Permalink
Browse files

Sortable: Return an empty URL param for empty sortable lists. Fixed #…

…5794 - sortable("serialize", {key: "foo[]"}) returns an empty string for an empty list
  • Loading branch information...
holger authored and scottgonzalez committed Jul 4, 2010
1 parent 325a262 commit 9d01ab564525f9112c2488ad257637593062b70d
Showing with 4 additions and 0 deletions.
  1. +4 −0 ui/jquery.ui.sortable.js
View
@@ -409,6 +409,10 @@ $.widget("ui.sortable", $.ui.mouse, {
if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2]));
});
+ if(!str.length && o.key) {
+ str.push(o.key + '=');
+ }
+
return str.join('&');
},

5 comments on commit 9d01ab5

@scottgonzalez

This comment has been minimized.

Show comment Hide comment
@scottgonzalez

scottgonzalez Dec 10, 2013

Member

@holger Can you please sign our CLA?

Member

scottgonzalez replied Dec 10, 2013

@holger Can you please sign our CLA?

@holger

This comment has been minimized.

Show comment Hide comment
@holger

holger Dec 12, 2013

Contributor

Done

Contributor

holger replied Dec 12, 2013

Done

@scottgonzalez

This comment has been minimized.

Show comment Hide comment
@scottgonzalez

scottgonzalez Dec 12, 2013

Member

Thanks.

Member

scottgonzalez replied Dec 12, 2013

Thanks.

@janekh

This comment has been minimized.

Show comment Hide comment
@janekh

janekh Jun 1, 2017

I know it's been several years but I just stumbled upon this when trying to use custom "key" with serialize method.

What was the actual reason this change was made? I would add couple of counter arguments why this change shouldn't have been made and should maybe even be reversed.

  1. There is now a difference in how ("serialize") and ("serialize", {key:"foo[]"}) work. There is no reason why those two should work differently. Either both should return "foo[]=" for empty lists or both should return empty string.

  2. When submitting HTML form with un-checked checkboxes they also do not generate empty values and have to be handled on server side. Just as submitting empty sortable list should be handled on server side. https://api.jquery.com/serialize/ doesn't include un-checked checkboxes in the resulting string. This is another difference in the JQuery universe.

  3. Most of the server side languages translate foo[]= as non empty array. Which is wrong considering that the sortable list was actually empty.

In case this is not going to be reversed, please update sortable documentation to reflect this anomaly and save the next person a lot of time trying to figure out what is going on.

@holger @scottgonzalez

I know it's been several years but I just stumbled upon this when trying to use custom "key" with serialize method.

What was the actual reason this change was made? I would add couple of counter arguments why this change shouldn't have been made and should maybe even be reversed.

  1. There is now a difference in how ("serialize") and ("serialize", {key:"foo[]"}) work. There is no reason why those two should work differently. Either both should return "foo[]=" for empty lists or both should return empty string.

  2. When submitting HTML form with un-checked checkboxes they also do not generate empty values and have to be handled on server side. Just as submitting empty sortable list should be handled on server side. https://api.jquery.com/serialize/ doesn't include un-checked checkboxes in the resulting string. This is another difference in the JQuery universe.

  3. Most of the server side languages translate foo[]= as non empty array. Which is wrong considering that the sortable list was actually empty.

In case this is not going to be reversed, please update sortable documentation to reflect this anomaly and save the next person a lot of time trying to figure out what is going on.

@holger @scottgonzalez

@scottgonzalez

This comment has been minimized.

Show comment Hide comment
@scottgonzalez

scottgonzalez Jun 1, 2017

Member

At this point, any change is a breaking change for code written in the past seven years. However, this plugin is scheduled for a complete rewrite, at which point every part of the API will be reviewed.

Member

scottgonzalez replied Jun 1, 2017

At this point, any change is a breaking change for code written in the past seven years. However, this plugin is scheduled for a complete rewrite, at which point every part of the API will be reviewed.

Please sign in to comment.