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!"