Skip to content

Instantly share code, notes, and snippets.

@mpwoodward
Created February 26, 2015 01:12
Show Gist options
  • Save mpwoodward/582d4542747c8a5f882c to your computer and use it in GitHub Desktop.
Save mpwoodward/582d4542747c8a5f882c to your computer and use it in GitHub Desktop.
Delete leave row function
function deleteLeaveRow(deleteLink) {
var totalFormsField = $('#id_form-TOTAL_FORMS');
var totalForms = parseInt(totalFormsField.val()) - 1;
totalFormsField.val(totalForms);
$(deleteLink).closest('.leaveForm').remove();
// for formset functionality to work properly, need to update all existing form ids so they're sequential
updateFormElementIndices('leaveForm');
// Have to destroy and rebind all the datepicker elements, otherwise they will be bound to the wrong
// form element as rows are added and removed.
$('.datepicker').each(function() {
$(this).datepicker('destroy');
$(this).datepicker({altFormat:"yy-mm-dd"});
});
if (totalForms == 0) {
$('#requestLeaveButton').addClass('disabled');
}
updateLeaveTotal();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment