43 lines
1.4 KiB
PHP
43 lines
1.4 KiB
PHP
<form method="method" action="{{ route('Shop.Searches.search') }}" id="search-general">
|
|
<div class="input-group">
|
|
@include('components.form.autocomplete', [
|
|
'name' => 'search',
|
|
'url' => route('Shop.Articles.autocomplete'),
|
|
'data' => [
|
|
'name' => $search['search_name'] ?? '',
|
|
],
|
|
])
|
|
<div class="input-group-append">
|
|
<span class="input-group-text"><i class="btn btn-sm fa fa-search"></i></span>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
@push('js')
|
|
<script>
|
|
$(function() {
|
|
const articleShowUrlTemplate = "{{ route('Shop.Articles.show', ['id' => '__ARTICLE_ID__']) }}";
|
|
|
|
$('#search-general .fa-search').click(function() {
|
|
$('#search-general').submit();
|
|
});
|
|
|
|
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>
|
|
@endpush
|