-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
79 additions
and
35 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
// This function should be called for any DataTable inside an HTML form that | ||
// contains form fields. This ensures that when the form is submitted, any form | ||
// fields that are hidden because of the DataTable paging/search/filter | ||
// functionality is still submitted with the form. | ||
function activateFormFieldsInDataTable( | ||
formSelector, // jQuery selector for the HTML form | ||
columnIndex, // column index in the DataTable that contains the form fields | ||
fieldType // form field type as a string (supported: 'checkbox', 'select') | ||
) { | ||
var form = $(formSelector); | ||
form.submit(function() { | ||
var cells = $(form).find('.datatable').DataTable().column(columnIndex).nodes(); | ||
for (var i = 0; i < cells.length; i++) { | ||
if (!document.body.contains(cells[i])) { | ||
var cell = $(cells[i]); | ||
if (fieldType == 'select') { | ||
var select = cell.find('select'); | ||
if (select.length > 0) { | ||
form.append('<input type="hidden" name="' + select[0].name + '" value="' + select.val() + '" />'); | ||
} | ||
} | ||
else if (fieldType == 'checkbox') { | ||
var checkbox = cell.find('input[type="checkbox"]')[0]; | ||
if (checkbox && checkbox.checked) { | ||
form.append('<input type="hidden" name="' + checkbox.name + '" value="on" />'); | ||
} | ||
} | ||
else { | ||
console.log('activateFormFieldsInDataTables: "' + fieldType + '" is not supported.'); | ||
} | ||
} | ||
} | ||
return true; | ||
}); | ||
} |
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,12 @@ | ||
<script> | ||
'use strict'; | ||
$(function() { | ||
var form = $('.modal form'); | ||
form.submit(function() { | ||
var cells = $('.modal .datatable').DataTable().column().nodes(); | ||
for (var i = 0; i < cells.length; i++) { | ||
var checkbox = cells[i].childNodes[0]; | ||
if (checkbox.checked) { | ||
checkbox.checked = false; | ||
form.append('<input type="hidden" name="' + checkbox.name + '" value="on" />'); | ||
} | ||
activateFormFieldsInDataTable('.modal form', 0, 'checkbox'); | ||
|
||
$('.modal .datatable tr').click(function(event) { | ||
if (event.target.type !== 'checkbox') { | ||
$(':checkbox', this).trigger('click'); | ||
} | ||
return true; | ||
}); | ||
|
||
$('.modal .datatable tr').click(function(event) { | ||
if (event.target.type !== 'checkbox') { | ||
$(':checkbox', this).trigger('click'); | ||
} | ||
}); | ||
}); | ||
</script> |
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