0

I have a live search in laravel 7 everything works good but I cant add (href a tag) to result list because result show in select option (select2 library) without (a) tag and cant be open in a new page for see result for this keyword

my blade:

   <div class="fre-search-wrap">
      <select class="livesearch form-control" name="Find Consultants"></select>
   </div>

my scripst:

<script type="text/javascript">
$('.livesearch').select2({
    placeholder: 'Select Consultants',
    ajax: {
        url: '/live_search/action',
        dataType: 'json',
        delay: 550,
        processResults: function (data) {
            return {
                results: $.map(data, function (item) {
                    return {
                        text: item.title,
                        id: item.id
                    }
                })
            };
        },
        cache: true
    }
});

the main source was this https://www.positronx.io/laravel-autocomplete-search-with-select2-example/

sara
  • 41
  • 5

1 Answers1

0

Hello guy you can use this to add a tag:


$('.livesearch').select2({
    placeholder: 'Select Consultants',
    ajax: {
        url: '/live_search/action',
        dataType: 'json',
        delay: 550,
        processResults: function (data) {
            return {
                results: $.map(data, function (item) {
                    return {
                        text: ""+item.title+"", // a tag
                        id: item.id
                    }
                })
            };
        },
        cache: true
    }
});
Sobhan
  • 13
  • 2
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 10 '21 at 17:25