$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;
+ $('form').off('submit.multiImageCheck').on('submit.multiImageCheck', function(e) {
+ let allRowsHaveImage = true;
- if (!hasImageInRow && !hasFilesSelected) {
+ $('.product-row').each(function() {
+ let row = $(this);
+ let hasImageInRow = row.find('.list-cell__images_row img').length > 0;
+
+ let fileInput = row.find('.list-cell__imageFiles input[type="file"]');
+ let hasFilesSelected = fileInput.length && fileInput[0].files.length > 0;
+
+ if (!hasImageInRow && !hasFilesSelected) {
+ allRowsHaveImage = false;
+ return false;
+ }
+ });
+
+ if (!allRowsHaveImage) {
e.preventDefault();
- alert('Пожалуйста, добавьте хотя бы одно фото перед сохранением.');
+ alert('Ð\9fожалÑ\83йÑ\81Ñ\82а, добавÑ\8cÑ\82е Ñ\85оÑ\82Ñ\8f бÑ\8b одно Ñ\84оÑ\82о в каждÑ\83Ñ\8e Ñ\81Ñ\82Ñ\80окÑ\83 пеÑ\80ед Ñ\81оÑ\85Ñ\80анением.');
return false;
}
});
});
JS;
+
$this->registerJs($js, \yii\web\View::POS_READY);
?>
+
<style>
.multiple-input-list .multiple-input-list__btn.js-input-plus {
width: 40px;