drag-check-js
drag-check-js copied to clipboard
Trigger onChange on click
When using onChange like described in README.md:
onChange: function(element) {
$(element).closest('td').css('background-color', element.checked ? '#73B355' : '#FFFACD');
}
The function is only triggered after dragging, not on click. It would be good to allow to also trigger onChange if the user only clicked one checkbox to allow a consistent callback. I tried to use clickToToggle: true for normal checkboxes but that just killed the check functionality at all on click (checkboxes are no more being checked).
I think this is expected behaviour in most cases. In the example above the table cells are only highlighted if they were dragged, but not if they were clicked, which is the same in result.
This is my jQuery workaround example, if it helps others. It uses the elements change event instead of dragCheck onChange ot act on every kind of change.
$('table :checkbox:not([readonly],[disabled])', context).change(function (e) {
$(this).closest('td').css('background-color', $(this).is(':checked') ? 'green' : 'yellow');
}).dragCheck();