From: Vladimir Fomichev Date: Tue, 19 Aug 2025 11:45:04 +0000 (+0300) Subject: Фильтры и даты X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=77e8e7389178b6a0b11744db42edfd8fc7b99cc3;p=erp24_rep%2Fyii-erp24%2F.git Фильтры и даты --- diff --git a/erp24/web/js/products1cNomenclatureActuality/index.js b/erp24/web/js/products1cNomenclatureActuality/index.js index 8d8ec792..8316b9b7 100644 --- a/erp24/web/js/products1cNomenclatureActuality/index.js +++ b/erp24/web/js/products1cNomenclatureActuality/index.js @@ -79,19 +79,24 @@ document.addEventListener("DOMContentLoaded", () => { $('#filter-date-from').on('change', function(){ var from = $(this).val(); var to = $('#filter-date-to'); + to.find('option').each(function(){ var val = $(this).val(); - if (val === '' || val >= from) { - $(this).show(); + $(this).toggle(val === '' || !from || val >= from); + }); + + var cur = to.val(); + if (from && (!cur || cur < from)) { + if (to.find(`option[value="${from}"]`).length) { + to.val(from).trigger('change'); } else { - $(this).hide(); + var firstVisible = to.find('option').filter(function(){ return $(this).is(':visible') && $(this).val(); }).first().val(); + if (firstVisible) to.val(firstVisible).trigger('change'); } - }); - if (to.val() && to.val() < from) { - to.val(from); } }); + $('.clear-btn').on('click', function(){ var target = $(this).data('target'); $('#' + target).val(null).trigger('change'); @@ -239,17 +244,22 @@ document.addEventListener("DOMContentLoaded", () => { const $to = fromSelect.closest('td').find('.to-month'); if (!$to.length) return; - // покажем только значения >= from (и пустую) $to.find('option').each(function(){ const val = $(this).val(); $(this).toggle(!val || !from || val >= from); }); const curTo = $to.val(); - if (from && curTo && curTo < from) { - $to.val(from); + if (from && (!curTo || curTo < from)) { + if ($to.find(`option[value="${from}"]`).length) { + $to.val(from).trigger('change'); + } else { + const firstVisible = $to.find('option').filter(function(){ return $(this).is(':visible') && $(this).val(); }).first().val(); + if (firstVisible) $to.val(firstVisible).trigger('change'); + } } } + });