Printing items per page in twig template not triggering form submit on views template

Created on 5 March 2024, 10 months ago
Updated 22 March 2024, 9 months ago

Problem/Motivation

I am overriding a view template to print the items_per_page select box at footer and the title search box at header section of template
I am using bef to enable auto-submit and hiding the submit button

Steps to reproduce

  • Create a view to show list of content
  • use the Full pager
  • Go to the setting for Full pager
  • In the Exposed option check the Allow user to control no. of items displayed in this view checkbox and leave the other option as it is
  • Now in filter Criteria add node title field and expose this field and save the view
  • Now override the view template in the twig template suggestion views-view--<view-id>.html.twig
    For example if view id is search then twig template name will be views-view--search.html.twig
  • Now copy the code from the base template
  • Now after the {{ pager }} add {{ exposed.items_per_page}} in overridden template to print only the select box after the pager
  • Now clear the cache and change the items per page dropdown. Observer the results its not updating

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

💬 Support request
Status

Closed: works as designed

Version

10.2

Component
Views 

Last updated 2 days ago

Created by

🇮🇳India nitesh624 Ranchi, India

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @nitesh624
  • This has steps to reproduce like a bug report but it is a support request.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    You are putting the select element outside the form tag

    The browser won't submit it unless you set the form attribute on the select to the id of the form element

    This isn't a Drupal thing, it's how browsers work

  • 🇮🇳India nitesh624 Ranchi, India

    So i need to do this via hook_preprocess_template right?

  • 🇮🇳India nitesh624 Ranchi, India

    Can you some example how to achieve this

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    You will likely need a hook form alter to modify the views exposed form and set the form attribute on the select field

    e.g.

    function YOURTHEME_form_views_exposed_form_alter(&$form) {
      $view = $form['#view'];
      $form['items_per_page']['#attributes']['form'] = $view->id();
    }
    

    Something like that

  • 🇮🇳India nitesh624 Ranchi, India

    ok thanks

  • Status changed to Closed: works as designed 10 months ago
  • 🇳🇱Netherlands Lendude Amsterdam
  • Instead of printing the 'Items per page' as {{exposed.items_per_page}}, print it by excluding any other exposed filters such as {{exposed|without('filter_name_one','filter_name_two','filter_name_three')}}.
    This is how I'm doing it:

    {% if pager %}
          <div class="col-md-10 ms-md-4">
            <div class="row d-flex align-items-center">
              <div class="col-md-8">
                {{ pager }}
              </div>
            {% if exposed %}
              <div class="col-md-4 d-flex align-items-center view-filters">
                <span class="me-md-2">{{'Show'|t}}</span>{{ exposed|without('field_question_right_category_target_id', 'field_state_transition_value') }}
              </div>
            {% endif %}
            </div>
          </div>
        {% endif %}
    
Production build 0.71.5 2024