]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-417
authormarina <m.zozirova@gmail.com>
Tue, 27 May 2025 12:14:06 +0000 (15:14 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 27 May 2025 12:14:06 +0000 (15:14 +0300)
erp24/views/write_offs_erp/_form.php

index 30ec400acb903d53a483e1009e92f486021b1718..c0fb4d2036c1f7d1c38f0fe00b5ff3ef42b38d70 100644 (file)
@@ -35,21 +35,22 @@ $this->registerJsFile('/js/validate/validateForm.js', ['position' => \yii\web\Vi
 $this->registerJsFile('/js/heic2any.min.js', ['position' => \yii\web\View::POS_END]);
 $this->registerJsFile('/js/heic_to_jpg_replace.js', ['position' => \yii\web\View::POS_END]);
 
-$this->registerJs(<<<JS
-document.addEventListener('DOMContentLoaded', function() {
-    const form = document.getElementById('my-upload-form');
-    const fileInput = form.querySelector('input[type="file"][name="image_name"]');
-
-    form.addEventListener('submit', function(e) {
-        if (!fileInput.files || fileInput.files.length === 0) {
-            alert('Пожалуйста, загрузите хотя бы один файл!');
+$js = <<<JS
+$(document).ready(function() {
+    $('form').on('submit', function(e) {
+        let hasImageInRow = $('.list-cell__images_row img').length > 0;
+        let fileInput = $('.list-cell__imageFiles input[type="file"]');
+        let hasFilesSelected = fileInput.length && fileInput[0].files.length > 0;
+
+        if (!hasImageInRow && !hasFilesSelected) {
             e.preventDefault();
+            alert('Пожалуйста, добавьте хотя бы одно фото перед сохранением.');
+            return false;
         }
     });
 });
-JS
-);
-
+JS;
+$this->registerJs($js, \yii\web\View::POS_READY);
 ?>
 <style>
     .multiple-input-list .multiple-input-list__btn.js-input-plus {