Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Fix issue with RegExp for getting context and replace context in blueprint #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions vendor/assets/javascripts/jquery_nested_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jQuery(function($) {

// Make the context correct by replacing <parents> 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]
Expand All @@ -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] + ']');
}
}
Expand Down