maxatwork / form2js

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

Ruby Style Arrays not Working #19

Open GeekTantra opened 12 years ago

GeekTantra commented 12 years ago

Ruby style arrays are not working for level 1 type arrays as follows:

testitem[test_property]

But it works for:

test.item[testproperty]

I guess the error is in

line 103

and

line 120

dharani commented 12 years ago

this still happens when when you have only one subelemnt,

testitem[testproperty] will not create a name property as testproperty: testpropertyvalue it is returned just the testpropertyvalue. Assuming the user has entered testpropertyvalue in the form for testproperty.

jstin commented 12 years ago

I'd add the following line to get Rails style arrays working.

name = name.replace(/\[([a-zA-Z_]*)\]/g, delimiter + '$1');

Add it below these lines around line number 98

value = nameValues[i].value;

if (skipEmpty && (value === '' || value === null)) continue;

name = nameValues[i].name;
name = name.replace(/\[([a-zA-Z_]*)\]/g, delimiter + '$1');
fmatosic commented 11 years ago

This works fine.