code: function (collection, elements, settings, index, oldIndex, newIndex) {
              var toReplace = new RegExp(pregQuote(settings.name_prefix + '[' + oldIndex + ']'), 'g');
              var replaceWith = settings.name_prefix + '[' + newIndex + ']';
  
              if (settings.children) {
                  $.each(settings.children, function (key, child) {
                      var childCollection = collection.find(child.selector).eq(index);
                      var childSettings = childCollection.data('collection-settings');
                      if (childSettings) {
                          childSettings.name_prefix = childSettings.name_prefix.replace(toReplace, replaceWith);
                          childCollection.data('collection-settings', childSettings);
                      }
                  });
              }
  
              replaceAttrData(elements, index, toReplace, replaceWith);
  
              toReplace = new RegExp(pregQuote(collection.attr('id') + '_' + oldIndex), 'g');
              replaceWith = collection.attr('id') + '_' + newIndex;
  
              if (settings.children) {
                  $.each(settings.children, function (key, child) {
                      var childCollection = collection.find(child.selector).eq(index);
                      var childSettings = childCollection.data('collection-settings');
                      if (childSettings) {
                          childSettings.elements_parent_selector = childSettings.elements_parent_selector.replace(toReplace, replaceWith);
                          childSettings.elements_selector = childSettings.elements_selector.replace(toReplace, replaceWith);
                          childSettings.prefix = childSettings.prefix.replace(toReplace, replaceWith);
                          childCollection.data('collection-settings', childSettings);
                      }
                  });
              }
  
              replaceAttrData(elements, index, toReplace, replaceWith);
          }
docs: replace element names and indexes in the collection, in Symfony, names are always in format CollectionType[field][42][value] and ids are in format CollectionType_field_42_value; so we need to change both.