'Autocomplete search with link on Name
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>
Solution 1:[1]
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>`
Solution 2:[2]
u can try executing a function on selecting the option
$('select').on('select2:select', function (evt) {
// get select value
//page redirection
});
Solution 3:[3]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | elmeddinkamalli |
| Solution 2 | core_dumps |
| Solution 3 | devilica |


