Near the end of the Sortable.serialize() method, there is a split command that splits on an underscore. What is the convention it''s following here and is it documented somewhere? Thanks, Jamie serialize: function(element) { element = $(element); var sortableOptions = this.options(element); var options = Object.extend({ tag: sortableOptions.tag, only: sortableOptions.only, name: element.id }, arguments[1] || {}); return $A(element.childNodes).collect( function(item) { return (encodeURIComponent(options.name) + "[]=" + encodeURIComponent(item.id.split("_")[1])); }).join("&"); }
Yeah, I saw that somewhere on the website but can''t find it anymore, well it is a wiki we could add it. You have to name the id of your element like that : element_0 Then the serialized table for your post will only have the number 0. I have different kind of element inside my container that I want to be sortable and only having a number is too restrictive for me so I had to rewrite the serialize method to return the full id instead. Can I ask you why did you design it like that ? Thanks, Jon. Jamie Orchard-Hays wrote:> Near the end of the Sortable.serialize() method, there is a split > command that splits on an underscore. What is the convention it''s > following here and is it documented somewhere? > > Thanks, > > Jamie > > serialize: function(element) { > element = $(element); > var sortableOptions = this.options(element); > var options = Object.extend({ > tag: sortableOptions.tag, > only: sortableOptions.only, > name: element.id > }, arguments[1] || {}); > return $A(element.childNodes).collect( function(item) { > return (encodeURIComponent(options.name) + "[]=" + > encodeURIComponent(item.id.split("_")[1])); > }).join("&"); > } > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Right, and if you have no underscore, or more than one, then it''s broken. In the first case, "undefined" is returned, and in the second case you get whatever value comes after the first underscore and before the second. Jamie On Oct 4, 2005, at 3:45 PM, Jonathan wrote:> Yeah, I saw that somewhere on the website but can''t find it > anymore, well it is a wiki we could add it. > > You have to name the id of your element like that : element_0 > Then the serialized table for your post will only have the number 0. > > I have different kind of element inside my container that I want to > be sortable and only having a number is too restrictive for me so I > had to rewrite the serialize method to return the full id instead. > > Can I ask you why did you design it like that ? > > Thanks, > Jon. > > Jamie Orchard-Hays wrote: > >> Near the end of the Sortable.serialize() method, there is a split >> command that splits on an underscore. What is the convention it''s >> following here and is it documented somewhere? >> >> Thanks, >> >> Jamie >> >> serialize: function(element) { >> element = $(element); >> var sortableOptions = this.options(element); >> var options = Object.extend({ >> tag: sortableOptions.tag, >> only: sortableOptions.only, >> name: element.id >> }, arguments[1] || {}); >> return $A(element.childNodes).collect( function(item) { >> return (encodeURIComponent(options.name) + "[]=" + >> encodeURIComponent(item.id.split("_")[1])); >> }).join("&"); >> } >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
http://wiki.script.aculo.us/scriptaculous/show/Sortable.serialize Am 04.10.2005 um 21:29 schrieb Jamie Orchard-Hays:> Near the end of the Sortable.serialize() method, there is a split > command that splits on an underscore. What is the convention it''s > following here and is it documented somewhere?