0

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>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mz1378
  • 1,957
  • 4
  • 20
  • 40

0 Answers0