form2js
form2js copied to clipboard
Ruby Style Arrays not Working
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
-
if (namePart.length > 1) -
if (namePart.length > 0)
and
line 120
-
arrIdx = namePart[k].match(/([a-z_]+)?[([a-z_][a-z0-9]+?)]/i); -
arrIdx = namePart[k].match(/([a-z_]+)?[([a-z_][a-z0-9_]+?)]/i);
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.
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');
This works fine.