cancel checkbox change
cancel checkbox change
I am using inline editor as in this example:
https://editor.datatables.net/examples/api/checkbox.html
However, when a checkbox is initially checked, I am using a modal box to confirm the user really wants it un-checked. The code works as far as cancelling the editing of the record, but, the checkbox continues to be unchecked until the dataTable is refreshed. I tried e.preventDefault() but that doesn't seem to work.
any ideas??
$('#SDPlus_BillableItems').on('change', 'input.editor-active', function (e) {
var tr = $(this).closest('tr');
var row = BillableItemsTable.row(tr);
thisRow = this;
selectedpkID = row.data().SDPlus_Worklogs.PK_ID;
approvedBy = row.data().SDPlus_Approvals.ApprovedBy;
if (approvedBy != null) {
e.preventDefault();
$('#alertModal').modal('show'); //only update if user confirms
return false;
} else {
updateRow();
}
});
$('#alertModal').on('click', '#modalButtonConfirm', function (e) {
updateRow();
$("#alertModal").modal("hide");
});
function updateRow() {
/*
the leftJoin on Approvals table assumes a record exists and does an update
I added a preEdit on the controller to insert the record first
if record already has a user name then they are un-checking the approved box
so tell the Controller to delete the record, not insert
*/
d = new Date($.now());
BillableItemsEditor
.edit($(thisRow).closest('tr'), false)
.set('SDPlus_Approvals.WorkLog_PK_ID', selectedpkID)
.set('SDPlus_Approvals.ApprovedBy', (approvedBy == null) ? userName : 'delete')
.set('SDPlus_Approvals.ApprovedDate', d)
.submit()
;
}
Answers
ahhh, nevermind...
I noticed I had
that is why .preventDefault() didn't work.
I changed it to .on('click' ... and everything appears to be working great.