Sunday, March 11, 2018

How to get data of a table with "readonly" elements - development

How to get data of a table with “readonly” elements

I’m trying to get all the elements of my table, it has a button that adds a row with editable inputs but also if its pressed the older inputs get the prop “readonly”. All of this is in a form with a submit button, the problem is that I cant get the data of the rows with “readonly” prop, but I do get the ones that are in a span

My js.

$('#form_trasferencia').submit(function (e) {
  e.preventDefault()
  var table = $('#tabla_transferencia')
  var salida = {}
  table.find('tr').each(function (i, el) {
    var $tds = $(this).find('td'),

    codigo = $tds.eq(0).val() || $tds.eq(0).text(),
    cantidad = $tds.eq(3).val() || $tds.eq(3).text(),
    costo_unit = $tds.eq(4).val() || $tds.eq(4).text(),
    total = $tds.eq(5).val() || $tds.eq(5).text(),

    aux = {'codigo': codigo, 'cantidad': cantidad, 'costo_unit': costo_unit, 'total': total}

   console.log(aux)
  })

My table

<table class="table table-striped table-bordered" id="tabla_transferencia">
  <thead>
    <tr>
      <th style="width: 80px">Codigo</th>
      <th style="width: 500px">Descripción</th>
      <th>Existencias</th>
      <th>Cantidad</th>
      <th>Costo/Unit</th>
      <th style="width: 40px">Total</th>
      <th></th>
    </tr>
  </thead>

  <tbody>
    <tr id='row0' class="datos_tabla_transferencia">
      <td><input type="text" id="txt_transferencia_codigo0" placeholder="Ingese el código" required></td>
      <td><span id="spn_transferencia_descripcion0"></span></td>
      <td><span id="spn_transferencia_existencias0"></span></td>
      <td><input type="number" id="txt_transferencia_cantidad0" placeholder="Cantidad" required readonly></td>
      <td><input type="text" id="txt_transferencia_costoUni0" placeholder="Costo/Unitario" required readonly></td>
      <td><span id="spn_transferencia_total0"></span></td>
      <td>
        <button type="button" id="0" data-id="row0" class="btn btn-danger
                                                        btn-xs remove">-
                                                </button>
      </td>
    </tr>
  </tbody>


</table>
<button id="btn_transferencia_nuevo" class="btn btn-default pull-left" disabled>
 Agregar
</button>

enter image description here
My output

enter image description here

Thx for the help



from Laravel Questions and Answers https://laravelquestions.com/laravel/how-to-get-data-of-a-table-with-readonly-elements/
via Lzo Media

No comments:

Post a Comment