maxatwork / form2js

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

Issue when using js2form #41

Open pnomolos opened 11 years ago

pnomolos commented 11 years ago

I have my form names in ruby-style syntax like a[b][c], but when using js2form the normalizeName process turns the object I pass into the a.b.c style names. This means that the input names to don't match the names the js2form function is creating for the object, so nothing gets filled in. Is this the intended behavior or am I missing something?

pnomolos commented 11 years ago

As a followup, this only occurs when you have ruby-style syntax one level deep (such as a[b]). I fixed this by adding the following code on lines 136-140 of form2js.js:

else if (/^\w+\[[a-z_][a-z0-9_]+?/.test(namePart))
{
    namePart = namePart[0].split('[', 2);
    nameParts.push(namePart[0], namePart[1].substr(0, namePart[1].length - 1));
}