let from = $("#dateFrom");
let to = $("#dateTo");
$('.select2').select2({ minimumResultsForSearch: Infinity });
$(document).on('focus', '.select2', function (e) {
if (e.originalEvent) {
$(this).siblings('select').select2('open');
}
});
$(function () {
from.datepicker({
dateFormat: DATE_FORMAT,
showButtonPanel: true,
showAnim: 'slideDown',
changeMonth: true,
changeYear: true,
})
.on("change", function () {
let date = fixDate($(this).val());
$(this).val(date.join('/'));
to.datepicker("option", "minDate", getDate($(this).val()));
})
.on("focus", function() {
this.select();
});
to.datepicker({
dateFormat: DATE_FORMAT,
showButtonPanel: true,
showAnim: 'slideDown',
changeMonth: true,
changeYear: true,
})
.on("change", function () {
let date = fixDate($(this).val());
$(this).val(date.join('/'));
from.datepicker("option", "maxDate", getDate($(this).val()));
})
.on("focus", function() {
this.select();
});
});
$(document).keypress(function (e) {
if (e.which == 13) {
$("#submitBtn").click();
}
});
let cat = $('#category');
let prop = $('#property');
cat.on('select2:select', function() {
updateProperties($(this));
})
function updateProperties(sel) {
if (sel.val() === 'A') {
prop.find('option[value="none"]').detach();
prop.find('option[value="business"]').detach();
prop.find('option[value="relaxation"]').detach();
if (prop.find('option[value="none"]').length == 0) {
prop.append($("", { value: 'none', text: 'Αναψυχής και ναυταθλητισμού' }));
}
if (prop.find('option[value="business"]').length == 0) {
prop.append($("", { value: 'business', text: 'Επαγγελματική χρήση' }));
}
} else {
prop.find('option[value="none"]').detach();
prop.find('option[value="business"]').detach();
if (prop.find('option[value="none"]').length == 0) {
prop.append($("", { value: 'none', text: 'Αναψυχής ιδιωτικής χρήσης' }));
}
if (prop.find('option[value="business"]').length == 0) {
prop.append($("", { value: 'business', text: 'Αλιευτικά επαγγελματικής χρήσης' }));
}
if (prop.find('option[value="relaxation"]').length == 0) {
prop.append($("", { value: 'relaxation', text: 'Λέμβοι αναψυχής επαγγελματικής χρήσης' }));
}
}
$('.select2').trigger("change");
}
updateProperties(cat);