1
Can you help me? I have the code further down working perfectly.
But when I put inside a modal, I can’t write inside the text field.
VIEW
<select class="itemName form-control" style="width:500px;" name="itemName" required></select>
<a href="#" id="rota" data-target="#modal" data-toggle="modal">Abrir chamado</a>
<div id="modal" class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"></h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
<table class="table table-sm table-striped table-hover">
<tr>
<td><b>categoria:</b></td>
<td>
<select class="itemName form-control" style="width:500px;" name="itemName"></select>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
Controller
public function index()
{
$conteudo = Suporte::OrderBy('status', 'asc')->paginate();
return view('suporte', ['conteudo' => $conteudo]);
}
public function dataAjax(Request $request)
{
$data = [];
if($request->has('q')){
$search = $request->q;
$data = Categoria::select("id","categoria")
->where('categoria','LIKE',"%$search%")
->get();
}
return response()->json($data);
}
Route
Route::get('/', 'suporteController@index');
Route::get('/select2-autocomplete-ajax', 'suporteController@dataAjax');
JS
<script>
$('.itemName').select2({
placeholder: 'Select an item',
ajax: {
url: 'select2-autocomplete-ajax',
dataType: 'json',
delay: 250,
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.categoria,
id: item.id
}
})
};
},
cache: true
}
});
</script>
Ajax packages
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
Try to remove the
tabindex="-1"
of the div of your modal.– sant0will
Dude, you’re a genius! How did you get this straight out? What is the functionality of "tabindex="-1" "?
– ShBr
Using tabindex, one can specify an explicit order for page elements
– ShBr
I’ve been through this problem before.
– sant0will