Search code examples
javascriptjquerylaravellaravel-livewire

laravel livewire wire:change does not fire


So i have a filter with mutliple tags. but whenever i select a 'tag' it wont fire to the function. And it does not matter where i put the wire:change, it just does not work.

First i had a basic Select dropdown, but then i changed it so i can select multiple tags to filter on.

blade code:

        <form >
  <div class="multiselect" >
    <div class="selectBox" onclick="showCheckboxes()">
      <select>
        <option>Select an option</option>
      </select>
      <div class="overSelect" wire:model="tag_id" wire:change="filter"></div>
    </div>
    <div id="checkboxes" >
      @foreach($categories as $category)
      <label >
        <input type="checkbox" value="{{$category->id}}" /> {{ $category->name}}
      </label>
      @endforeach
    </div>
  </div>
</form>

javascript for the dropdown:

   <script>
        var expanded = false;


        function showCheckboxes() {
  var checkboxes = document.getElementById("checkboxes");
  if (!expanded) {
    checkboxes.style.display = "block";
    expanded = true;
  } else {
    checkboxes.style.display = "none";
    expanded = false;
  
  }

}
    </script>

css for the dropdown:

    <style>
       .multiselect {
  width: 200px;
}

.selectBox {
  position: relative;
}

.selectBox select {
  width: 100%;
  font-weight: bold;
}

.overSelect {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}

#checkboxes {
  display: none;
  border: 1px #dadada solid;
}

#checkboxes label {
  display: block;
}

#checkboxes label:hover {
  background-color: #1e90ff;
}
</style>

It used to work before i altered the dropdown to multiselect


Solution

  • Your wire:model and wire:change are not on your select tag, but on the div below it. Move it to your select tag:

    <select wire:model="tag_id" wire:change="filter">
        <option>Select an option</option>
    </select>
    <div class="overSelect"></div>