From 1a6fc0a908d3bde0d6cc950ce27fbb13971102f9 Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 3 Jun 2025 09:45:10 +0300 Subject: [PATCH] ERP-417 --- erp24/web/js/validate/validateForm.js | 70 +++++++++++++-------------- 1 file changed, 33 insertions(+), 37 deletions(-) diff --git a/erp24/web/js/validate/validateForm.js b/erp24/web/js/validate/validateForm.js index 70bf779c..0350ff77 100755 --- a/erp24/web/js/validate/validateForm.js +++ b/erp24/web/js/validate/validateForm.js @@ -1,6 +1,5 @@ $(".form-validate button").click(function (e) { e.preventDefault(); - var form = $(this).closest('form')[0]; var yiiform = $("#" + form.id); @@ -26,52 +25,46 @@ $(".form-validate button").click(function (e) { let errors = data.errors || {}; - // Получаем группу и имя пользователя - let group = $('.group-name').text().trim(); - let currentUser = $('.admin-name').text().trim(); - let selectedStoreId = $('#writeoffserp-store_id').val(); - let commentValue = $('#writeoffserp-comment').val().trim(); + const rows = $('.multiple-input-list__item'); + + let allRowsHaveImage = true; + rows.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; + } + }); - const specialStoreIds = ['1', '9', '28']; // Ванеева, Народная, Революции - const allowedCommentUsers = [ - 'Емельянова Ольга', - 'Яшенкова Алена', - 'Цветкова Ольга' - ]; + if (!allRowsHaveImage) { + if (!errors['__common']) errors['__common'] = []; + errors['__common'].push('Пожалуйста, добавьте хотя бы одно фото к каждому списанию перед сохранением.'); + } - if (group === 'IT' && specialStoreIds.includes(selectedStoreId)) { - // Проверка фото или файлов - let allRowsHaveImage = true; - - $('.multiple-input-list__item').each(function () { - const row = $(this); - const hasImage = row.find('.list-cell__images_row img').length > 0; - const fileInput = row.find('.list-cell__imageFiles input[type="file"]'); - const hasFile = fileInput.length > 0 && fileInput[0].files.length > 0; - - if (!hasImage && !hasFile) { - allRowsHaveImage = false; - return false; // break .each - } - }); + // Добавляем проверку комментария только для группы IT и спец магазинов + const group = $('.group-name').text().trim(); + const currentUser = $('.admin-name').text().trim(); + const selectedStoreId = $('#writeoffserp-store_id').val(); + const commentValue = $('#writeoffserp-comment').val().trim(); - if (!allRowsHaveImage) { - if (!errors['__common']) errors['__common'] = []; - errors['__common'].push('Пожалуйста, добавьте хотя бы одно фото к каждой строке.'); - } + const specialStoreIds = ['1', '9', '28']; + const allowedCommentUsers = ['Емельянова Ольга', 'Яшенкова Алена', 'Цветкова Ольга']; - // Запрет комментария + if (group === 'IT' && specialStoreIds.includes(selectedStoreId)) { if (commentValue.length > 0 && !allowedCommentUsers.includes(currentUser)) { errors['WriteOffsErp[comment]'] = [ - 'Комментарий могут писать только: ' + allowedCommentUsers.join(', ') + 'Комментарий могут заполнять только: ' + allowedCommentUsers.join(', ') + '.' ]; } } - // Обработка ошибок + console.log('Ошибки перед alert:', errors); + if (Object.keys(errors).length > 0) { renderErrors(errors); - let allErrors = []; for (const key in errors) { if (Array.isArray(errors[key])) { @@ -81,6 +74,8 @@ $(".form-validate button").click(function (e) { } } + console.log('Собранные ошибки для alert:', allErrors); + alert(allErrors.join('\n')); } else { yiiform.off('submit'); @@ -88,7 +83,7 @@ $(".form-validate button").click(function (e) { } }) .fail(function () { - console.log("Не удалось выполнить запрос к серверу"); + console.log("не удалось выполнить запрос к серверу"); }); return false; @@ -112,6 +107,7 @@ $(".form-validate button").click(function (e) { } }); - $('.messages').html(messages.join(',
')); + var strOut2 = messages.join(',
'); + $('.messages').html(strOut2); } }); \ No newline at end of file -- 2.39.5