Hi, I have an issue with change input radio field name.

Input:
I have some elements with class "box". Each box div include some form fields (<input> text, checkbox, radio). This box have sortable by jQuery UI extension. Drag box element up or down.
Each input have name like box-[indexNumber][fieldName]. Before sortable boxes their have ascending indexNumber, started by 0.

Output:
After drag box element It shoud change input name indet to achive ascending index number, start by 0 for the first bo, [1] for second. [2] for third, etc.

I have added a function that change input after drag box element. But now my function has issue that the first input radio with value "Option 1" set [tmp] and after [1] number index, it should be [0] index.

I have used [tmp] for reason that my first box change to the index that old box have this index and radio input disappear checked (marked input disappear on front view).

Javascript Code:
Code:
$(document).ready(function() {
$('.container').find('.box').each(function(idx) {
  $(this).find('input').each(function() {
    let field = $(this);
    let fieldName = field.attr('name');
    let mIndex = 0;
    let fieldNameMatch = fieldName.match(/(.+)\[(\d+)](.+)/);
    let fieldTmp = $('.container').find('[name="' + fieldNameMatch[1] + '[' + idx + ']' + fieldNameMatch[3] + '"]');

    console.log(field);

    /* Tmp */
    fieldTmp.each(function() {
      $(this).attr('name', fieldNameMatch[0].replace(/\[\d+]/, '[tmp]'));
      $(this).attr('id', $(this).attr('name').replace(/[\[\]]/g, '#').replace(/\#+/g, '-').replace(/[-]+$/g, ''));
      $(this).closest('.field').children('label').attr('for', $(this).attr('id'));
    });

    /* Field */
    field.attr('name', fieldNameMatch[0].replace(/\[\d+]/g, function(match, pos, original) {
      return mIndex++ === 0 ? '[' + idx + ']' : match;
    }));
    field.attr('id', field.attr('name').replace(/[\[\]]/g, '#').replace(/\#+/g, '-').replace(/[-]+$/g, ''));
    field.closest('.field').children('label').attr('for', field.attr('id'));

    /* Tmp index */
    fieldTmp.each(function() {
      $(this).attr('name', fieldNameMatch[0].replace(/\[\w+]/, '[' + fieldNameMatch[2] + ']'));
      $(this).attr('id', $(this).attr('name').replace(/[\[\]]/g, '#').replace(/\#+/g, '-').replace(/[-]+$/g, ''));
      $(this).closest('.field').children('label').attr('for', $(this).attr('id'));
    });

  });
});
});
https://jsfiddle.net/pbLkabhe/4/

How can I fix it?