Hi Richard, I could have sworn I opened a doc ticket on this about two weeks ago, when someone else ran into the fact that the docs say it "...returns a hash..." (which it does, in the lower-case general sense of the word -- all POJOs are hashes; it doesn't return a Hash).
But it looks like I never got around to it. I'll open one (lighthouse seems to be having issues at the minute), and fix it next week when I'll have a chance to blast through all my open docs tickets... If you want to file a separate enhancement request on lighthouse for having it return a Hash, feel free. I think, though, that it's probably not going to be changed to do that -- it's going to get changed in another way (array or some such) because of the issue that serialize() doesn't maintain the order of fields or allow multiple fields with the same name, both of which it Really Should Do. :-) FWIW, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Feb 17, 3:35 pm, Richard Quadling <[email protected]> wrote: > Hello. > > I'm having problems using the Hash.merge() method on a Form.serialize(true). > > What I want to do is ... > > parameters : $('formUserAdmin').serialize(true).merge({Action : > 'ClientAddUser', JSONP:'tabUA_UpdateUserIDs'}); > > But it isn't working because the output of the serialize method is not > a true Hash, like you would get from $H(). > > Using ... > > parameters : $H($('formUserAdmin').serialize(true)).merge({Action : > 'ClientAddUser', JSONP:'tabUA_UpdateUserIDs'}); > > is working as I would expect. > > But I don't know if I should be doing that as I was expecting the > serialize() method to return a hash. > > As always, there are 2 fixes. > > 1 - Correct the documentation to reflect the behaviour. > 2 - Fix the code. > > I think the fix is in src/dom/form.js, line 28 which currently reads ... > > return options.hash ? data : Object.toQueryString(data); > > and maybe should read ... > > return options.hash ? $H(data) : Object.toQueryString(data); > > Now, if a user is already $H() the form.serialize(true), then this > still seems to be OK. > > $H($H($H($H($H($('formUserAdmin').serialize(true)).merge({Foo:'bar'}))))).inspect() > > provides the same output as ... > > $H($('formUserAdmin').serialize(true)).merge({Foo:'bar'}).inspect() > > which, with the patch applied is now the same as ... > > $('formUserAdmin').serialize(true).merge({Foo:'bar'}).inspect() > > With this patch, the documentation now agrees with the code. > > In looking at the unit tests, I think the reason this has not been > seen is in unittest.js > > function assertHashEqual(expected, actual, message) { > expected = $H(expected); > actual = $H(actual); > var expected_array = expected.toArray().sort(), actual_array = > actual.toArray().sort(); > message = buildMessage(message || 'assertHashEqual', 'expected: > <?>, actual: <?>', expected, actual); > // from now we recursively zip & compare nested arrays > function block() { > return expected_array.length == actual_array.length && > expected_array.zip(actual_array).all(assertPairEqual); > } > this.assertBlock(message, block); > } > > Both the expected and actual are converted to $H()'d. Which means they > will match. > > Only the expected should be $H()'d as it the actual should already be > $H()'d by prototype. > > I hope that makes sense and is right, if not, I'll stick with $H()-ing > my serialized form. > > Regards, > > Richard. > > -- > ----- > Richard Quadling > Zend Certified Engineer :http://zend.com/zce.php?c=ZEND002498&r=213474731 > "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
