Просмотр исходного кода

gestionale - aggiornato testo select anno se selezionata stagione nei mesi

ferrari 2 месяцев назад
Родитель
Сommit
ea5f9c0f49
1 измененных файлов с 24 добавлено и 3 удалено
  1. 24 3
      resources/views/livewire/records_in_out.blade.php

+ 24 - 3
resources/views/livewire/records_in_out.blade.php

@@ -15,14 +15,14 @@
 
         <form action="" class=" d-flex align-items-center ">
 
-            <select class="form-select form-select-lg me-1 " id="month" style="width:150px !important;">
-                <option value="x" {{$month == "x" ? 'selected' : ""}}>Anno completo</option>
+            <select class="form-select form-select-lg me-1 " id="month" style="width:150px !important;" onchange="updateYearSelect(this)">
+                <option value="x" {{$month == "x" ? 'selected' : ""}}>Stagione</option>
                 @foreach(getMonthList() as $mid => $mname)
                     <option value="{{$mid}}" {{$month == $mid ? 'selected' : ""}}>{{$mname}}</option>
                 @endforeach
             </select>
 
-            <select class="form-select " style="width:100px !important;" id="year">
+            <select class="form-select " {{-- style="width:100px !important;" --}} id="year">
                 @for($y=date("Y") + 5; $y>date("Y") - 2; $y--)
                     <option value="{{$y}}" {{$y == date("Y") ? 'selected' : ''}}>{{$y}}</option>
                 @endfor
@@ -503,6 +503,27 @@
             @this.exportYear(y);
         });
 
+        function updateYearSelect(month) {
+            let year = document.getElementById("year");
+
+            if (year) {
+                let options = Array.from(year.options);
+
+                if (month.value=='x') {
+                    options.forEach(option => {
+                        let y = Number(option.innerText);
+                        if (!isNaN(y)) {
+                            option.innerText = `${y}/${y+1}`;
+                        }
+                    });
+                } else {
+                    options.forEach(option => {
+                        let y = option.innerText;
+                        option.innerText = y.split('/')[0];
+                    });
+                }
+            }
+        }
 
     </script>