onchange - jQuery change event fired only once - editableTableWidget and autoNumeric plugins -
i'm using 2 plugins: autonumeric , editabletablewidget. first format currency , second let user edit table. need combine them when user edit table, currency auto formatted.
the problem change event fired once each cell id import, if try edit more once time currency not formatted
that's html
<table id="preview"> <tbody> <tr> <td id="date"></td> <td id="description"></td> <td id="import"></td> <th id="total"></th> --> not editable </tr> <tr> <td id="date"></td> <td id="description"></td> <td id="import"></td> <th id="total"></th> --> not editable </tr> <tr> <td id="date"></td> <td id="description"></td> <td id="import"></td> <th id="total"></th> --> not editable </tr> </tbody> </table>
that's jquery
$('#preview').editabletablewidget().tableformat().find('tbody').focus(); $.fn.tableformat = function () { 'use strict'; var element = $(this) element.find('td').on('change', function () { if ($(this).is("#import")) { $(this).autonumeric('init', {asep: '.', adec: ','}); return; } }) return this; };
i read these posts:
i don't know if best solution, work. before initialize autonumeric "init" , "update" this:
$('#preview').editabletablewidget().tableformat().find('tbody').focus(); $.fn.tableformat = function () { 'use strict'; var element = $(this) element.find('td').on('change', function () { $(this).autonumeric('init', {asep: '.', adec: ','}); if ($(this).is("#import")) { $(this).autonumeric('update', {asep: '.', adec: ','}); return; } }) return this; };
Comments
Post a Comment