templates/blog/_testFilter.html.twig line 1
<div class="test-filter-box"><h3>Hledat v testech</h3><form method="GET" action="#" class="test-filter-form" onsubmit="return submitFilter()"><div class="filter-row"><div class="filter-field"><label for="manufacturer">Značka</label><select id="manufacturer" name="manufacturer" onchange="updateModels()"><option value="">Vyberte značku</option>{% for manufacturer in manufacturers %}<option value="{{ manufacturer.url }}" data-id="{{ manufacturer.id }}"{% if activeManufacturer and activeManufacturer.url == manufacturer.url %}selected{% endif %}>{{ manufacturer.name }}</option>{% endfor %}</select></div><div class="filter-field"><label for="model">Model</label><select id="model" name="model"><option value="">Vyberte model</option>{% if models %}{% for model in models %}<option value="{{ model.url }}"{% if activeModel and activeModel.url == model.url %}selected{% endif %}>{{ model.name }}</option>{% endfor %}{% endif %}</select></div><div class="filter-field"><button type="submit" class="filter-button">Vyhledat</button></div></div></form></div><script>function updateModels() {const manufacturerSelect = document.getElementById('manufacturer');const modelSelect = document.getElementById('model');const selectedOption = manufacturerSelect.options[manufacturerSelect.selectedIndex];const manufacturerId = selectedOption ? selectedOption.getAttribute('data-id') : null;// Clear model optionsmodelSelect.innerHTML = '<option value="">Vyberte model</option>';if (!manufacturerId) {return;}fetch('/models?idManufacturer=' + encodeURIComponent(manufacturerId)).then(response => response.json()).then(data => {if (data.models) {data.models.forEach(model => {const option = document.createElement('option');option.value = model.url;option.textContent = model.name;modelSelect.appendChild(option);});}}).catch(error => {console.error('Error fetching models:', error);});}function submitFilter() {const manufacturerSelect = document.getElementById('manufacturer');const modelSelect = document.getElementById('model');const manufacturerUrl = manufacturerSelect.value;const modelUrl = modelSelect.value;hideErrorMessage();if (!manufacturerUrl) {alert('Vyberte prosím značku');return false;}let url = '/clanky/testy-aut/';if (manufacturerUrl && modelUrl) {url += manufacturerUrl + '-' + modelUrl;} else if (manufacturerUrl) {url += manufacturerUrl;}window.location.href = url;return false;}function hideErrorMessage() {const errorMessage = document.getElementById('filter-error-message');if (errorMessage) {errorMessage.style.display = 'none';}}</script>