From 7585dd3e31890a2cb49db79ef016159e559eefcd Mon Sep 17 00:00:00 2001 From: Mikhail Mikhaliov Date: Tue, 9 Oct 2012 16:06:20 +0300 Subject: [PATCH] Fix replace context ids in blueprint --- vendor/assets/javascripts/jquery_nested_form.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/assets/javascripts/jquery_nested_form.js b/vendor/assets/javascripts/jquery_nested_form.js index 31b0df16..082b84b6 100644 --- a/vendor/assets/javascripts/jquery_nested_form.js +++ b/vendor/assets/javascripts/jquery_nested_form.js @@ -14,7 +14,7 @@ jQuery(function($) { // Make the context correct by replacing with the generated ID // of each of the parent objects - var context = ($(link).closest('.fields').closestChild('input, textarea').eq(0).attr('name') || '').replace(new RegExp('\[[a-z]+\]$'), ''); + var context = ($(link).closest('.fields').closestChild('input, textarea').eq(0).attr('name') || '').replace(new RegExp('\\[[a-z]+\\]$'), ''); // context will be something like this for a brand new form: // project[tasks_attributes][1255929127459][assignments_attributes][1255929128105] @@ -27,11 +27,11 @@ jQuery(function($) { for(var i = 0; i < parentNames.length; i++) { if(parentIds[i]) { content = content.replace( - new RegExp('(_' + parentNames[i] + ')_.+?_', 'g'), + new RegExp('(_' + parentNames[i] + ')_\\d+_', 'g'), '$1_' + parentIds[i] + '_'); content = content.replace( - new RegExp('(\\[' + parentNames[i] + '\\])\\[.+?\\]', 'g'), + new RegExp('(\\[' + parentNames[i] + '\\])\\[\\d+\\]', 'g'), '$1[' + parentIds[i] + ']'); } }