Is there a way to turn a form into a complex JavaScript object based some structured form?
Now, I have no idea if this should be done in a better way, but basically I want something like this:
<form>
<input name="Foo" value="1" />
<input name="Parent.Child1" value="1" />
<input name="Parent.Child2" value="2" />
</form>
and I want this in JavaScript:
var form = GetForm();
var obj = ConvertFormToComplexObject(form);
//
// Followings should be true
//
// obj.Foo == 1;
// obj.Parent != null
// obj.Parent.Child1 == 1;
// obj.Parent.Child2 == 2;
//
Any suggestions?
Thanks,
I wrote a plugin to do just that.
Hope it will help someone out there.
Let me know if you find any bugs.
Here’s the code for serializeObject.js:
Here’s the test: