0

I want to click on name in search box and open profile of that person. How can I add link on this item.firstname. My route for user profile is '/users/{id}'..

this is my javascript code for autocomplete

<script type="text/javascript">
        $('.livesearch').select2({
            placeholder: 'Search users',
            ajax: {
                url: '/master/autocomplete',
                dataType: 'json',
                delay: 250,
                processResults: function (data) {
                    return {
                        results: $.map(data, function (item) {
                            return {
                                text: item.firstname+' '+item.lastname,
                                id: item.id,

                            }
                        })
                    };
                },
                cache: true,
            }
        });
    </script>

enter image description here

ADyson
  • 57,178
  • 14
  • 51
  • 63

3 Answers3

0

Don't know if it works but you can try adding a tag instead of text like

text: `<a href='/users/item.id'>${item.firstname} ${item.lastname}</a>`
0

u can try executing a function on selecting the option

$('select').on('select2:select', function (evt) {
   // get select value
  //page redirection
});
  • how to add this in my javascript code, I am not so familiar with javascript –  Apr 19 '22 at 13:10
0

enter image description here

There is answer... I hope so that it can be helpful to someone..

  • Next time try to add code in textual form instead of an image. [Read why](//meta.stackoverflow.com/q/285551) – RiveN Apr 20 '22 at 10:20