From b766e82e4be44b6027d05527ff59f7bb652cb2fa Mon Sep 17 00:00:00 2001 From: f Date: Wed, 2 May 2018 15:18:05 -0300 Subject: [PATCH] no intentar ordenar tablas que no existen --- app/assets/javascripts/drag.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/drag.js b/app/assets/javascripts/drag.js index 0ebd534..9a1b605 100644 --- a/app/assets/javascripts/drag.js +++ b/app/assets/javascripts/drag.js @@ -1,7 +1,11 @@ $(document).on('turbolinks:load', function() { + var table = document.querySelector('.table-draggable'); + + if (table == null) return; + var were = $('.order.was').map(function() { return $(this).data('order') }); - tableDragger(document.querySelector('.table-draggable'), { + tableDragger(table, { mode: 'row', onlyBody: true, dragHandler: '.handle' @@ -9,7 +13,7 @@ $(document).on('turbolinks:load', function() { // Al soltar, reordenamos toda la tabla $('.post_order').val(function(i,v) { return were[i]; }); // Mostramos el nuevo orden tambiƩn - $('.order.is').text(function(i,v) { console.log(i, were[i]); return were[i]; }); + $('.order.is').text(function(i,v) { return were[i]; }); // Solo mostramos el valor anterior si no coincide con el valor // actual. Como lo mostramos entre comillas, usamos el atributo // data-order del