I need to enable single-click selection of a multi listbox without using additional components and by using JavaScript. Is it possible? And how?
<InputSelect @bind-Value="@testModel.SelectedIds">
<option value="1">Hello</option>
<!-- ... -->
</InputSelect>
I built another function, but it does not work (Note: in Blazor serverside, the post that is presented as a solution works partially: it selects the many options, but since the option is not clicked, @bind-Value won't update the ienumerable variable):
<script>
var already_done = false;
$(function () {
$('body').on('mousedown', 'select[multiple] option', function (e) {
if (already_done) {
already_done = false;
return;
}
e.preventDefault();
already_done = true;
this.dispatchEvent(new MouseEvent("click", { ctrlKey: true }));
return false;
});
});
</script>