I am using Select2 for the project. The second selection box is populated depending on the selected item in the first field, as shown in the link below. However, for some reason, I cannot click on the first item in the second selection field. The only way to select the first item if I want is to first select another user, and then return to the first. How can i solve this?
Video:

My code is:
This is the first selection field populated with regular PHP (Laravel). Everything is fine here.
<div class="form-group"> <label for="select"> Partner: </label> <select id="select" name="select" class="searchselect searchselectstyle"> @foreach($partners as $i => $partner) <option {{$i == 0 ? 'selected' : ''}} value="{{$partner->id}}">{{$partner->name}}</option> @endforeach </select> </div>
Here is the second error checkbox.
<div class="form-group" > <label for="select2"> Hoofdgebruiker: </label> <select id="select2" style="min-width: 200px;" name="select2" class="searchselect searchselectstyle"> </select> </div> <script type="text/javascript"> $(document).ready(function(){ var url = '/json/getusers'; var $post = {}; $post.id = $("select").val(); $.ajax({ type: "POST", dataType: "json", url: url, data: $post, cache: false }).done(function(data){ $('#select2') .find('option') .remove() .end(); $.each(data, function(i, value) { console.log(data); $('#select2').append($('<option>').text(value.text).attr('value', value.id)); }); } ); });
-
public function getusers(){ if(!isset($_POST['term'])){ $users = User::where('partner_id', $_POST['id'])->get(); }else{ $wildcard = '%'.$_POST['term'].'%'; $users = User::where('partner_id', $_POST['id'])->where('email', 'LIKE', $wildcard)->get(); } $array = array(); foreach($users as $i => $user){ $array[$i] = array("id" => $user->id, "text" => $user->email); } return response()->json($array); }
source share