tr.nested-fields td = f.input :tipo, label: false, collection: Contabilidade::MapeamentoManual.tipos_i18n, value_method: :second, label_method: :first, include_blank: 'Selecione', input_html: { class: 's2' } td = f.input :anexo, label: false, collection: Contabilidade::MapeamentoManual.anexos_i18n, value_method: :second, label_method: :first, include_blank: 'Selecione', input_html: { class: 's2 anexo' } td = f.input :linha, label: false, collection: Contabilidade::MapeamentoManual.linhas_i18n, value_method: :second, label_method: :first, include_blank: 'Selecione', input_html: { class: 's2 linha' } td = f.input :coluna, label: false, as: :string, input_html: { class: 'total' } td = f.input :mes, label: false, collection: Contabilidade::MapeamentoManual.mes_i18n, value_method: :second, label_method: :first, include_blank: 'Selecione', input_html: { class: 's2' } td = f.input :valor, label: false, as: :string, input_html: { class: 'valor', data: { autonumeric: true, 'a-sep'=> '.', 'a-dec'=>',', 'a-sign'=> 'R$ ', 'v-min'=> '0.00', 'v-max'=> '9999999999.99' } } td.center = link_to_remove_association " Remover", f, class: "btn btn-sm btn-danger icone-anular" javascript: function limpaSelectBox(id){ select_box = $(id).empty().select2({ placeholder: "Selecione", allowClear: true }) select_box.prepend(new Option('Selecione', '', true, true)); select_box.trigger('change'); return(select_box); } function populaSelectBox(select_box){ select_box.prepend(new Option('Selecione', '', true, true)); select_box.trigger('change'); } $('.anexo').change(function(){ atualiza_lista_de_linha($(this)) }); function atualiza_lista_de_linha(campo) { var linha = campo.closest("tr"); var anexo = $('.anexo', linha).val() if (anexo == '') { anexo = 'vazio' } var url = root_url + "contabilidade/periodos_matriz_de_saldos_contabeis/" + anexo + "/linha_de_campos_para_mapeamentos_manuais_filtrado"; select_box = $('.linha', linha) limpaSelectBox(select_box); $.ajax({ type: 'GET', url: url, success: function(data,status,xhr) { if ($.trim(data) != ""){ $.each(data, function (i, item) { option = new Option(item, i); select_box.append(option); }); populaSelectBox(select_box); } } }); } $(function () { $('form').on('cocoon:after-insert', function(e, insertedItem) { $('select.s2', insertedItem).select2(); }) $('form').on('cocoon:after-remove', function(e, removedItem) { $('input[data-autonumeric]', removedItem).val('0'); $('input[type="hidden"][id$="_val"]', removedItem).val('0'); }); });