HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/farmfun.komma.pro/resources/js/site/components/searchFormHandler.js
/* ==========================================================================
   Search form
 ========================================================================== */

const SearchFormHandler = {

    form: null,

    init: function () {

        SearchFormHandler.form = document.querySelector('.js-search-form');

        if(!isset(SearchFormHandler.form)) return;

        const searchLocation = SearchFormHandler.form.querySelector('.js-search-location');

        SearchFormHandler.form.addEventListener('submit', function (e) {
            if(searchLocation.value === '') {
                searchLocation.classList.add('c-select--alert');
                e.preventDefault();
            }
        });

        if(SearchFormHandler.form.classList.contains('js-search-form-on-change')) {
            const formFields = SearchFormHandler.form.querySelectorAll('select, input');
            for(let i = 0; i < formFields.length; i++) {
                const formField = formFields[i];
                formField.addEventListener('change', function () {
                    if(searchLocation.value !== '') {
                        SearchFormHandler.form.submit();
                    }
                });
            }
        }
    },
};

SearchFormHandler.init();