Fixed snippet chooser pagination for non searchable snippets

Pagination links are generated from the search form action.

This change always puts the search form into the HTML, but removes the search box and submit button when the snippet is not searchable.

The user doesn't see the form and the pagination links work again.
This commit is contained in:
Karl Hobley 2015-08-26 16:38:12 +01:00
parent 2242244c4b
commit 94565bac8a
2 changed files with 7 additions and 5 deletions

View file

@ -3,16 +3,18 @@
{% include "wagtailadmin/shared/header.html" with title=choose_str subtitle=snippet_type_name icon="snippet" %}
<div class="nice-padding">
{% if is_searchable %}
<form class="snippet-search search-bar" action="{% url 'wagtailsnippets:choose' content_type.app_label content_type.model %}" method="GET">
{# Need to keep the form in the HTML, even if the snippet is not searchable #}
{# This is to allow pagination links to be generated from the form action URL #}
<form class="snippet-search search-bar" action="{% url 'wagtailsnippets:choose' content_type.app_label content_type.model %}" method="GET">
{% if is_searchable %}
<ul class="fields">
{% for field in search_form %}
{% include "wagtailadmin/shared/field_as_li.html" with field=field %}
{% endfor %}
<li class="submit"><input type="submit" value="{% trans 'Search' %}" /></li>
</ul>
</form>
{% endif %}
{% endif %}
</form>
<div id="search-results" class="listing snippets">
{% include "wagtailsnippets/chooser/results.html" with choosing=1 %}

View file

@ -30,7 +30,7 @@ function initModal(modal) {
function setPage(page) {
var dataObj = {p: page, results: 'true'};
if ($('#id_q').val().length) {
if ($('#id_q').length && $('#id_q').val().length) {
dataObj.q = $('#id_q').val();
}