new: make click in choices of search box load the page of the product

This commit is contained in:
Valentin Lab
2025-10-04 13:54:21 +02:00
parent c338a8afc7
commit f2a87f4d12
2 changed files with 21 additions and 4 deletions

View File

@@ -16,11 +16,27 @@
@push('js') @push('js')
<script> <script>
$(function() { $(function() {
const articleShowUrlTemplate = "{{ route('Shop.Articles.show', ['id' => '__ARTICLE_ID__']) }}";
$('#search-general .fa-search').click(function() { $('#search-general .fa-search').click(function() {
$('#search-general').submit(); $('#search-general').submit();
}); });
initAutocomplete('#search_name'); function redirectToArticle(item, evt) {
if (!item || typeof item.value === 'undefined' || item.value === null || item.value === '') {
return;
}
if (evt) {
evt.preventDefault();
evt.stopPropagation();
}
const targetUrl = articleShowUrlTemplate.replace('__ARTICLE_ID__', item.value);
window.location.href = targetUrl;
}
initAutocomplete('#search_name', redirectToArticle);
}); });
</script> </script>
@endpush @endpush

View File

@@ -13,9 +13,10 @@
var id = item.value; var id = item.value;
$('#' + field).val(id); $('#' + field).val(id);
if (typeof(callback) != 'undefined') { if (typeof callback === 'function') {
var c = callback + '(' + id + ')'; callback.call(this, item, evt);
eval(c); } else if (typeof callback === 'string' && callback.length && typeof window[callback] === 'function') {
window[callback].call(this, item, evt);
} }
}); });
} }