Skip to content

Commit 35a2cf0

Browse files
committed
fix js when regexp doesn't match
1 parent 6939ec1 commit 35a2cf0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

vendor/assets/javascripts/jquery_nested_form.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
var context = ($(link).closest('.fields').closestChild('input, textarea, select').eq(0).attr('name') || '').replace(/\[[a-z_]+\]$/, '');
1818

1919
// If the parent has no inputs we need to strip off the last pair
20-
var current = content.match(new RegExp('\\[([a-z_]+)\\]\\[new_' + assoc + '\\]'))[1];
20+
var current = content.match(new RegExp('\\[([a-z_]+)\\]\\[new_' + assoc + '\\]'));
2121
if (current) {
22-
context = context.replace(new RegExp('\\['+current+'\\]\\[(new_)?\\d+\\]$'), '');
22+
context = context.replace(new RegExp('\\[' + current[1] + '\\]\\[(new_)?\\d+\\]$'), '');
2323
}
2424

2525
// context will be something like this for a brand new form:

vendor/assets/javascripts/prototype_nested_form.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ document.observe('click', function(e, el) {
1111
var context = (el.getOffsetParent('.fields').firstDescendant().readAttribute('name') || '').replace(/\[[a-z_]+\]$/, '');
1212

1313
// If the parent has no inputs we need to strip off the last pair
14-
var current = content.match(new RegExp('\\[([a-z_]+)\\]\\[new_' + assoc + '\\]'))[1];
14+
var current = content.match(new RegExp('\\[([a-z_]+)\\]\\[new_' + assoc + '\\]'));
1515
if (current) {
16-
context = context.replace(new RegExp('\\['+current+'\\]\\[(new_)?\\d+\\]$'), '');
16+
context = context.replace(new RegExp('\\[' + current[1] + '\\]\\[(new_)?\\d+\\]$'), '');
1717
}
1818

1919
// context will be something like this for a brand new form:

0 commit comments

Comments
 (0)