Saturday, December 25, 2010

Prototype Form.serialize

A short comment that took hours of debugging only to discover it wasn't me, it was the documentation. Who would have guessed that this works on the name of the element, not the id?

Prototype Form.serialize()
This serializes the name, not the id of the element(s).

In these examples from the prototype docs, the element name is "username", "age", "hobbies". 
The form id="person-example".
$('person-example').serialize()
// -> 'username=sulien&age=22&hobbies=coding&hobbies=hiking'
$('person-example').serialize(true)
// -> {username: 'sulien', age: '22', hobbies: ['coding', 'hiking']}

No comments:

Post a Comment