form2js icon indicating copy to clipboard operation
form2js copied to clipboard

Ruby Style Arrays not Working

Open GeekTantra opened this issue 14 years ago • 3 comments

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);
    

GeekTantra avatar Nov 12 '11 00:11 GeekTantra

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.

dharani avatar Jan 03 '12 13:01 dharani

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');

jstin avatar Jan 17 '12 23:01 jstin

This works fine.

fmatosic avatar Jan 27 '13 20:01 fmatosic