Created
February 26, 2015 01:12
-
-
Save mpwoodward/582d4542747c8a5f882c to your computer and use it in GitHub Desktop.
Delete leave row function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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