<commit_before>= simple_form_for(model_object, :url => url, :html => {:class => 'carnival-form container-fluid'}) do |f|
  = render "carnival/shared/form/inner_form", button: button, model_object: model_object, presenter: presenter, :url => url, :action => action, :f => f

  .submit_button
    = f.submit button, disable_with: t('please_wait'), class: 'submit'

:javascript
  var nestedForms = {};
  $(document).ready(function(){
    nestedForm = $(".nested-form-list .form-new-association").each(function(index, element){
      nestedForms[getFormName(element)] = element;
      element.remove();
    });

    $(".existing-options").hide();
    $(".nested-form-subtitle").hide();
  });

  function createNewForm(selector, form, target){
    $(".nested-form-subtitle").show();

    newForm = $(nestedForms[form]).clone().wrap("<div>").parent();
    $(newForm).find(".select2-container").remove();
    $(newForm).find("select").removeClass("select2-offscreen");
    $(newForm).find("select").show();

    newForm = $(newForm).html()
    var container = $(target).parents("." + form).find(selector);
    var last_index = container.children("li").length;
    newForm = replaceInputIndexes(newForm, form, container, last_index);

    container.append(newForm);
    container.find("li:last")[0].scrollIntoView(true)
    container.find("li:last .carnival-select").select2({width: '100%'});

    setupDateFields();
    var lastFormAdded = container.find(".nested-form-list-item").last();
    lastFormAdded.find('.select2-remote').each(function(){
      addSelect2ToField(this);
    });
  }

  function replaceInputIndexes(newForm, form, container, index){
    newForm = newForm.replace(new RegExp("(_" + form + "_attributes_)\\d+(_[a-zA-Z]+)", "g"), "$1" + index + "$2");
    newForm = newForm.replace(new RegExp("(\\[" + form + "_attributes\\]\\[)\\d+(\\]\\[[a-zA-Z_]+\\])", "g"), "$1" + index + "$2");

    if (container.parents('.nested-form-list').length){
      var parent = container.parents('.nested-form-list');
      var parentForm = getFormName(parent.children(":first"));
      var parentIndex = container.parents('li').index();

      newForm = replaceInputIndexes(newForm, parentForm, parent, parentIndex);
    }    

    return newForm;
  }

  function getFormName(element){
    var classes = $(element).parent().attr("class").split(" ");
    classes.splice(classes.indexOf("nested-form-list"), 1);
    return classes[0];
  }

  function removeNestedFormElement(element){
    $(element).parent().parent().hide();
    $(element).parents("li").find(".destroy").val("1");
  }

  function toggleNestedForm(element){
    $(element).parent().parent().find("ul.nested-form-list").toggle();
    if($(element).text() == "#{t('nested_form.close')}")
      $(element).text("#{t('nested_form.open')}");
    else
      $(element).text("#{t('nested_form.close')}");
    $(".existing-options").toggle();
  }

  function renderSelectOptions(selector){
    $(selector).show();
  }
  function removeRelationOption(id, selectId){
    $('#'+id+'_options').hide();
    $('#'+id).attr('checked', false);
    $('#'+id+'_select_option').prop('disabled', false);
    //$('#'+selectId).trigger("chosen:updated");
  }



  function getNestedFormOptions(params){
    $('#nested_form_options_'+params['field_name']).html();
    var elemId = params['scope_html_id'];
    var scopeValue = $('#'+elemId).val();

    var key = params['scope_name'];
    params['carnival_list_scope'] = {};
    params['carnival_list_scope'][key] = scopeValue;

    $.ajax({
      url: params['url'],
      data: params,
      success: function(data){
        $('#nested_form_options_'+params['field_name']).html(data.template);
        var $select = $('#nested_form_options_'+params['field_name']).find('select');
        updateNestedFormSelectHtml($select, params['has_new_action']);
      }
    });
  }

  function updateDependentFormSelectHtml(load_dependent_path, presenter, value, field, dependentField){
    if(value != ""){
      $.ajax(load_dependent_path + "/" + presenter + "/" + dependentField + "/" + field + "/" + value)
        .done(function(data){
          var selector = "select.field-" + dependentField.replace("_id", "");
          $(selector).html(data);
          //$(selector).trigger("chosen:updated");
        })
        .error(function(err, data){
          console.log("updateDependentFormSelectHtml ajax error " + err);
        });
    }
  }

  function updateNestedFormSelectHtml($select, hasNewAction){
    $select.css({width: $select.parent().css("width")})
    if(!hasNewAction)
      return;
    $select.chosen(
    {
      create_option_text: 'Criar',
      create_option: function(){createNewForm('.nested-form-list.'+params['field_name'], params['field_name'])}
    });
  }
<commit_msg>Fixed remove item from multiple nested forms<commit_after>= simple_form_for(model_object, :url => url, :html => {:class => 'carnival-form container-fluid'}) do |f|
  = render "carnival/shared/form/inner_form", button: button, model_object: model_object, presenter: presenter, :url => url, :action => action, :f => f

  .submit_button
    = f.submit button, disable_with: t('please_wait'), class: 'submit'

:javascript
  var nestedForms = {};
  $(document).ready(function(){
    nestedForm = $(".nested-form-list .form-new-association").each(function(index, element){
      nestedForms[getFormName(element)] = element;
      element.remove();
    });

    $(".existing-options").hide();
    $(".nested-form-subtitle").hide();
  });

  function createNewForm(selector, form, target){
    $(".nested-form-subtitle").show();

    newForm = $(nestedForms[form]).clone().wrap("<div>").parent();
    $(newForm).find(".select2-container").remove();
    $(newForm).find("select").removeClass("select2-offscreen");
    $(newForm).find("select").show();

    newForm = $(newForm).html()
    var container = $(target).parents("." + form).find(selector);
    var last_index = container.children("li").length;
    newForm = replaceInputIndexes(newForm, form, container, last_index);

    container.append(newForm);
    container.find("li:last")[0].scrollIntoView(true)
    container.find("li:last .carnival-select").select2({width: '100%'});

    setupDateFields();
    var lastFormAdded = container.find(".nested-form-list-item").last();
    lastFormAdded.find('.select2-remote').each(function(){
      addSelect2ToField(this);
    });
  }

  function replaceInputIndexes(newForm, form, container, index){
    newForm = newForm.replace(new RegExp("(_" + form + "_attributes_)\\d+(_[a-zA-Z]+)", "g"), "$1" + index + "$2");
    newForm = newForm.replace(new RegExp("(\\[" + form + "_attributes\\]\\[)\\d+(\\]\\[[a-zA-Z_]+\\])", "g"), "$1" + index + "$2");

    if (container.parents('.nested-form-list').length){
      var parent = container.parents('.nested-form-list');
      var parentForm = getFormName(parent.children(":first"));
      var parentIndex = container.parents('li').index();

      newForm = replaceInputIndexes(newForm, parentForm, parent, parentIndex);
    }    

    return newForm;
  }

  function getFormName(element){
    var classes = $(element).parent().attr("class").split(" ");
    classes.splice(classes.indexOf("nested-form-list"), 1);
    return classes[0];
  }

  function removeNestedFormElement(element){
    $(element).parent().parent().hide();
    $(element).parents("li:first").find(".destroy").val("1");
  }

  function toggleNestedForm(element){
    $(element).parent().parent().find("ul.nested-form-list").toggle();
    if($(element).text() == "#{t('nested_form.close')}")
      $(element).text("#{t('nested_form.open')}");
    else
      $(element).text("#{t('nested_form.close')}");
    $(".existing-options").toggle();
  }

  function renderSelectOptions(selector){
    $(selector).show();
  }
  function removeRelationOption(id, selectId){
    $('#'+id+'_options').hide();
    $('#'+id).attr('checked', false);
    $('#'+id+'_select_option').prop('disabled', false);
    //$('#'+selectId).trigger("chosen:updated");
  }



  function getNestedFormOptions(params){
    $('#nested_form_options_'+params['field_name']).html();
    var elemId = params['scope_html_id'];
    var scopeValue = $('#'+elemId).val();

    var key = params['scope_name'];
    params['carnival_list_scope'] = {};
    params['carnival_list_scope'][key] = scopeValue;

    $.ajax({
      url: params['url'],
      data: params,
      success: function(data){
        $('#nested_form_options_'+params['field_name']).html(data.template);
        var $select = $('#nested_form_options_'+params['field_name']).find('select');
        updateNestedFormSelectHtml($select, params['has_new_action']);
      }
    });
  }

  function updateDependentFormSelectHtml(load_dependent_path, presenter, value, field, dependentField){
    if(value != ""){
      $.ajax(load_dependent_path + "/" + presenter + "/" + dependentField + "/" + field + "/" + value)
        .done(function(data){
          var selector = "select.field-" + dependentField.replace("_id", "");
          $(selector).html(data);
          //$(selector).trigger("chosen:updated");
        })
        .error(function(err, data){
          console.log("updateDependentFormSelectHtml ajax error " + err);
        });
    }
  }

  function updateNestedFormSelectHtml($select, hasNewAction){
    $select.css({width: $select.parent().css("width")})
    if(!hasNewAction)
      return;
    $select.chosen(
    {
      create_option_text: 'Criar',
      create_option: function(){createNewForm('.nested-form-list.'+params['field_name'], params['field_name'])}
    });
  }

{'fraction_non_alphanumeric': 0.2058363731109953, 'fraction_numerical': 0.003335070349140177, 'mean_word_length': 3.979761286974572, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2758334', 'n_tokens_mistral': 3005, 'n_tokens_neox': 2964, 'n_words': 446}