javascript - Chunk ruby on rails text_field name with jQuery -


if have rails form output following html name attribute

"recipe[ingredients_attributes][1][quantities_attributes][0][measurement]" 

how can split chunks jquery, can manipulate integers. avoid use of regular expression if possible.

i have similar function rails form helper id attributes follows

function reindexquantid(existing, parentindex, index) {     var str = existing.split('_');     str[1] = parentindex;     str[3] = index;     return str.join('_'); } 

this 1 easier because characters delimited _

the following uses regex:

var regex = new regexp("\[[a-z0-9_]*\]", "g"); var array = existing.match(regex); array[1] = "[42]"; array[3] = "[007]"; return array.join("");  # "recipe[ingredients_attributes][42][quantities_attributes][007][measurement]" 

the array returned regex before manipulation follows:

["recipe[ingredients_attributes]", "[1]", "[quantities_attributes]", "[0]", "[measurement]"] 

please note i'm not experienced regex, there may better match, code works.

p.s. noticed sparda's comment, seems need.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -