Score:0

Pager element not showing on form

in flag

I have a simple tableselect element inside my form and the tableselect rows are populated using a pager as follows:

$pagerLimit = 10; //default value if nothing is passed in
$query = $this->jobSkillStorage->getQuery();
$query->condition('type', $skillType);   
$query->pager($pagerLimit)
$ids = $query->execute();
$jobSkills = $this->jobSkillStorage->loadMultiple($ids);  

return $jobSkills;

The pagination limit functions well and only 10 results are returned, however the pagination controls do not show after the tableselect. Please see the full code of how the tableselect was generated.

public function buildForm(array $form, FormStateInterface $form_state) {

  $form['vtabs'] = [
    '#type' => 'vertical_tabs',
  ];

  $form['tech_skills' = [
    '#type' => 'details',
    '#title' => $this->t('Tech Skills'),
    '#group' => 'vtabs',
    'tech_skills_table' => [
      '#type' => 'tableselect',
      '#empty' => $this->t('Your search for tech skills did not return '
          . 'any results.'),  
      '#header' => [
        'name' => $this->t('SKILL NAME'),
        'description' => $this->t('DESCRIPTION'),
        'status' => $this->t('STATUS'),
        'changed' => $this->t('LAST UPDATED'),
        'actions' => $this->t('ACTIONS')  
      ],
      '#options' => $this->getTableOptions(),          
    ],
    'tech_skills_pager' => [
      '#theme' => 'pager',     
    ],         
  ];

  return $form;

Most examples of paging I see use $build['pager'] rather than $form['pager']. I'm just wondering if pager isn't a form renderable element? Could that be the reason its not showing? Kinda lost on this. Any thoughts please?

Thanks

Kevin avatar
in flag
The code above has syntax issues.
ilechcod avatar
in flag
Pls At what point exactly?
Score:0
de flag

I believe you need to use #theme rather than #type. #type is for form elements, #theme is for themeable elements, that are outside (and also sometimes inside) forms.

As another example, table is a #theme, whereas tableselect, which is a table with form elements, is a #type.

ilechcod avatar
in flag
Hey Jaypan, that's a good one. Thanks for speedy answer. I've just changed ```'type' => 'pager'``` to ```'theme' => 'pager' ``` and the pager still doesn't show and I need a tableselect because I need selectable rows. Isn't there a way to use pager with tableselect element?
Jaypan avatar
de flag
Did you use the hashtag? `#theme` not `theme`
ilechcod avatar
in flag
Yes I did ```'#theme' => 'pager'```. I'm going to update the question with my current code shortly. Really pissed off I can't get something so simple to work!
Jaypan avatar
de flag
Maybe move the pager into a render array outside the form.
ilechcod avatar
in flag
I'm still struggling to get this to work, folks. This should be stuff that works out of the box, what am I doing wrong? Pls has anybody else been able to use a pager with a tableselect?
Jaypan avatar
de flag
Did you try moving the pager render array out of the form?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.