# Cakephp: using select2 to filter data in a report

**URL:** <https://discourse.cakephp.org/t/cakephp-using-select2-to-filter-data-in-a-report/4584>\
**Category:** Need Help\
**Created:** [July 17, 2018, 3:23pm UTC](https://discourse.cakephp.org/t/cakephp-using-select2-to-filter-data-in-a-report/4584 "2018-07-17T15:23:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mben](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mben/32/1099_2.png) [@mben](https://discourse.cakephp.org/u/mben)\
**Post date:** [July 17, 2018, 3:23pm UTC](https://discourse.cakephp.org/t/cakephp-using-select2-to-filter-data-in-a-report/4584/1 "2018-07-17T15:23:56Z")

</div>

I have a report to generate: Assignments by room, in which I need to filter rooms with an autocomplete behavior. I wanted to adapt the code of [jquery select2](https://select2.org/getting-started/basic-usage) to my code, but failed:

```
<select class="js-example-basic-single" name="state">
  <option value="AL">Alabama</option>
  .....
  <option value="WY">Wyoming</option>
</select>

<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>

<?php $this->append('script'); ?>
<script>
 $(document).ready(function() {
    $('.js-example-basic-single').select2();
});
</script>
<?php $this->end(); ?>

```

In my report view, I have something like this to find a list of rooms:

```
<?php
    /** @var \App\View\AppView $this */
    $inputOptions = isset($inputOptions) ? $inputOptions : [];
    $searchInputs = $this->Search->inputs($searchParameters, $inputOptions);
    $searchInputs['room_id']['required'] = false;
    $searchInputs['room_id']['empty'] = true;
    $formOptions = isset($formOptions) ? $formOptions : [];
    if (empty($formOptions['id'])) {
        $formOptions['id'] = 'search-form';
    }
    $formOptions['templates'] = [
        'inputContainer' => '<div class="col-sm-2 form-group {{type}}{{required}}">{{content}}{{help}}</div>',
    ]

    ?>
    <div class="row">
        <?= $this->Form->create(null, $formOptions); ?>
        <?= $this->Form->inputs($searchInputs, ['fieldset' => false]); ?>
        <div class="col-sm-2"
             style="padding-top:25px;"><?= $this->Form->button('Search', ['type' => 'submit', 'class' => 'btn btn-primary']); ?></div>
        <?= $this->Form->end(); ?>
    </div>

```

In my Assignments controller / initialize, I wrote:

```
        $parameters = [
        ['name' => 'serial_number', 'className' => 'Input'],
        ['name' => 'model_number', 'className' => 'Input'],
        ['name' => 'ip_address', 'className' => 'Input', 'formConfig' => ['label' => 'IP Address']],

if ($this->request->param('action') == 'reportRoom') {
        $rooms = $this->AssetsAssignations->Rooms->find('list')->order(['name' => 'asc']);
        $this->set(compact('rooms'));
        $parameters = [
            ['name' => 'room_id', 'className' => 'Select', 'class'=>'js-example-basic-single', 'formConfig' => ['label' => 'Room'],
                'finder' => $rooms
            ],
        ];
    }
    $this->loadComponent('PlumSearch.Filter', ['parameters' => $parameters]);

```

I wanted to assign ‘class’=\>‘js-example-basic-single’, in my controller but seems not working. In my view, I could not transform \<?= $this-\>Form-\>inputs($searchInputs, ['fieldset' =\> false]); ?\> using :

Any help please ?
