I’m trying to rename some fields in a clone function, but I’m not sure how to rename (increase) the field name.
var tr = $copy.clone();
tr('input').each(function() {
console.log(this.name);
this.name = something;
});
Example of field name:
field[subform][0][subsubform][2][name]
In this case I would need to increase [2] to [3]. The name could have more or less brackets, but it’s always the second last one that I would need to increase.
How do I go about doing this?
Regular expression fun. Matches a pattern [number][string]end Of line, reads the number, adds one, joins other part of match, and sets the new name.