0
I have the select
with search field and with all selected default values, as shown:
$(document).ready(function() {
$(".meuselect").select2();
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/css/select2.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.10/js/select2.min.js"></script>
<div style="margin-top: 4%;">
<form action="post">
<select style="width:300px;" data-placeholder="Selecione Utente" class="form-control meuselect" name="Utente[]" id="Utente" multiple>
<option value="UM" selected="selected">UM</option>
<option value="Dois" selected="selected">Dois</option>
<option value="Três" selected="selected">Três</option>
<option value="Quatro" selected="selected">Quatro</option>
<option value="Cinco" selected="selected">Cinco</option>
<option value="Seis" selected="selected">Seis</option>
<option value="Sete" selected="selected">Sete</option>
<option value="Oito" selected="selected">Oito</option>
<option value="Nove" selected="selected">Nove</option>
<option value="Dez" selected="selected">Dez</option>
<option value="Onze" selected="selected">Onze</option>
<option value="Doze" selected="selected">Doze</option>
<option value="Treze" selected="selected">Treze</option>
</select>
</form>
</div>
The result inside the combobox is this way:
I wanted everything to be the same as in the picture, but instead of the X checkboxes appear marked, for example in this image:
but the idea was to remove the "X" and get a checkbox as I put in the second image, it is possible?
– Bruno
@Bruno Cara, I was wrong, I got it wrong, I Edited the answer. Anyway, checkbox does not make sense, since once you click on it it disappears from the screen, so it does not make sense to use it, since you can not use it and uncheck it, since at the first click it would be gone
– hugocsl
but look at this example, it appears like this: first user view form and so User deepen visualization](https://i.stack.Imgur.com/09jVJ.jpg), that’s what I meant. But in this way, the possibility of searching (possibility of writing the name) as in the example above, we no longer have. It is possible to do so?
– Bruno
@Bruno believe not, then you would have to change the CSS as I changed you would have to also change the Javascript of the plugin, he would have to when creating the list ul/li, also create a checkbox, and still "lynch" this checkbox with the list options, I believe it is something very complex to be done, I suggest you look for another component of select if you want an option of this type... or else you will have to manjar A lot of JS to do it you want
– hugocsl
and there will be another select component that meets what I’m looking for?
– Bruno
@Bruno I think you were not very clear in your question, so I do not understand what you wanted... however this link should help you, I think it is what you are looking for https://codepen.io/faur/pen/vWVPGE
– hugocsl
@hugocsl yes, that’s what I’m looking for
– Bruno