$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 {