maxatwork / form2js

Javascript library for collecting form data
http://maxatwork.github.com/form2js/
MIT License
640 stars 137 forks source link

Array index does not match form index #3

Open n0rad opened 13 years ago

n0rad commented 13 years ago

If you have addresses[1].street with a addresses[0].street that does not exists or is empty the result index of [1].street will be [0].street

maxatwork commented 13 years ago

It's not a bug, array index must be unique to distinct different array items, but not used directly, document order is used instead (see readme). Why do you want to keep specified indexes?

n0rad commented 13 years ago

to use js object for validation and reinject errors into html element

maxatwork commented 13 years ago

You can set skipEmpty parameter to false, so it will not skip empty entries, should be enough for validation/error reinjection.

n0rad commented 13 years ago

Its not enough because in a dynamic form with tabs that you dynamically add and remove you may have a final result with an index [1] and [3] without a [0] and [2] for exemple

maxatwork commented 13 years ago

Make array with 'undefined' elements ([0] and [2]) is not ok too. Probably some deserialization method with some hook/callback function can solve this problem, will try to make something.