Skip to content

Commit

Permalink
Support pagination with multiple forms
Browse files Browse the repository at this point in the history
Allow to specify the HTML form id even when the pagination is not a
child of the form.
  • Loading branch information
kofrezo committed Mar 26, 2024
1 parent 2e3ac30 commit 005d996
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 10 additions & 2 deletions serveradmin/common/static/js/serveradmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $(document).ready(function() {
}

// This is our progress spinner we can call e.g. spinner.enable() from
// everywhere when ever we need it for example when doing long running
// everywhere when ever we need it for example when doing long-running
// ajax requests for the servershell search.
window.spinner = {
_timers: {},
Expand Down Expand Up @@ -43,7 +43,15 @@ $(document).ready(function() {
// submitting the links.
$('.pagination.form a').each(function(index, anchor) {
anchor.onclick = function(event) {
let form = this.closest('form');
let form = null;
let formId = this.closest('.pagination').dataset.formId;
if (formId) {
form = document.getElementById(formId);
}
else {
this.closest('form');
}

if (form) {
event.preventDefault();

Expand Down
13 changes: 9 additions & 4 deletions serveradmin/common/templates/pagination.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
{# Usage: {% include "pagination.html" with page=obj form=False %} #}
{# Usage expamples: #}
{# {% include "pagination.html" with page=obj form=False %} #}
{# {% include "pagination.html" with page=obj form=True %} #}
{# {% include "pagination.html" with page=obj form=True form_id="myform" %} #}

{# Set form parameter to True to make the pagination controls find the #}
{# form it is enclosed and submit it with the page parameter appended. #}
{# Set form parameter to True to make the pagination controls find the form it #}
{# is enclosed and submit it with the page parameter appended. If there are #}
{# multiple forms you can set form_id to the HTML id of the form that should #}
{# get submitted. #}

<div class="pagination {% if form %}form{% endif %}">
<div class="pagination {% if form %}form{% endif %}" {% if form_id %}data-form-id="{{ form_id }}"{% endif %}>
<span class="step-links">
{% if page.has_previous %}
<a href="?page=1">&laquo; first</a>
Expand Down

0 comments on commit 005d996

Please sign in to comment.