2

Estoy creando unas tablas que agreguen filas, el asunto es que ya esta "solucionado", el problema es que cuando doy al botón agregar fila, lo que tenia escrito antes en las filas agregadas se me elimina, el asunto es que no se quiere que por cada fila agregada se vaya guardando por que es un formulario largo y seria muy tedioso estar escribe y guarda, etc....

asi se ve cuando estoy agregando texto: introducir la descripción de la imagen aquí

así se ve luego a lo que presiono en el botón "+" para agregar mas filas introducir la descripción de la imagen aquí

ESTO ES LO QUE TENGO EN HTML

<div><strong>1.1.4. Personas involucradas</strong></div>
                <div style="font-size:small; margin-bottom: 15px;"></div>
                      <!-- tabla 1.1.4  -->
                        <div class="table-responsive">
                          <table class="table" id="tabla114">
                            <thead>
                                <tr class="t-arriba text-center centro-letra">
                                  <td>Personas, instituciones, empresas u organismos involucrados</td>
                                  <td>Cómo lo afectaría la eliminación el problema ¿positivo ó negativo?</td>
                                  <td>Motivo por el que estaría afectado o alcanzado si el problema se suprimiera</td>
                                  <td class="boton-agregar"><i class='fa fa-plus'onclick="crearLinea114({{$cant_e114}})"></i></td>
                                </tr> 
                            </thead>
                            <tbody class="t-abajo" id="tbody_anexos114">
                              @php ($cant = 1)
                              @foreach ($e114 as $it114)
                              <tr class="tr_lista114" id="tr114_{{$cant}}">
                                  <td> <textarea  onkeyup="auto_grow(this)" name="e114_involucrado[]">{{$it114->e114_involucrado}}</textarea> </td>
                                  <td> <textarea  onkeyup="auto_grow(this)" name="e114_impacto[]">{{$it114->e114_impacto}}</textarea></td>
                                  <td> <textarea  onkeyup="auto_grow(this)" name="e114_motivo[]">{{$it114->e114_motivo}}</textarea> </td>
                                  <td class="boton-eliminar"> <i class="fas fa-trash-alt" title="Eliminar fila"  onclick="eliminar_linea('tr114_{{$cant}}')"></i> </td>
                              </tr>
                              @php ($cant++)
                              @endforeach
                            </tbody>
                          </table>
                        </div>

Y ESTO ES EL JS EL QUE HACE EL TRABAJO DE CREAR LAS FILAS. el asunto es, que estoy generando un nuevo tbody, entonces "ataca" todo los y que se van creando y eso hace que lo que no este guardado se refresque.

function crearLinea114(variable){
    lista_anexos = document.getElementsByClassName('tr_lista114')

    if (variable > 0){ siguiente114  = variable } else siguiente114 = 0 

    if(lista_anexos.length >0) siguiente114 = (lista_anexos[lista_anexos.length-1].getAttribute('id')).split('_')[1]
    siguiente114++

    tbody_anexos114.innerHTML+=`<tr class="tr_lista114" id="tr114_${siguiente114}">
                                <td> <textarea   name="e114_involucrado[]"></textarea> </td>
                                <td> <textarea   name="e114_impacto[]"></textarea></td>
                                <td> <textarea   name="e114_motivo[]"></textarea> </td>
                                <td class="boton-eliminar"> <i class="fas fa-trash-alt" title="Eliminar fila" onclick="eliminar_linea('tr114_${siguiente114}')"></i> </td
                            </tr>`
}
1
  • 2
    Con innerHTML están sustituyendo el contenido HTML del <tbody> por el que le estés pasando. Para sumarle el <tr> a lo que ya hay debes usar appendChild.
    – phpMyGuel
    el 9 sep. 2019 a las 8:25

0

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Examina otras preguntas con la etiqueta o formula tu propia pregunta.