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 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 ?