Saturday, October 28, 2017

Django Template and compating with select option value

Hello everyone.
I hace a ListView-based class with attribute `paginate_by = 12`.
There is in HTML-template a select element with seveeral options, for pagination of course. Options come to the page from context. Loks like this:
`
<select  onchange="location.href='?results_per_page='+value;">
{% for item in per_page_options %}
    <option value="{{ item }}"
        {% if request.GET.results_per_page == item or paginate_by == item %}
        selected="selected" {% endif %}
        >{{ item }}
    </option>
{% endfor %}
</select>
`

When i change value of select attribute `paginate_by` changes succesfully and on page another option is selected, according to new value of `paginate_by'
But when i move to another page on this template the value 'selection' stops working and in "options" the first value becomes "selected".
Even tried to check how this template reads the "context" from "view", by adding this code next on page
`
{% if request.GET.results_per_page == paginate_by %}
    <h5>{{ paginate_by }} - {{ request.GET.results_per_page }}</h5>
{% endif %}
`
And after changing the page I can see this new string. Like 3 - 3 or 9 - 9, etc.

Looks like some bug. But never saw it before.
Any ideas?

Thanks anyway.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bb7eeb52-8a29-474a-9607-3cc9f108b1dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment