$(".form-validate button").click(function (e) {
e.preventDefault();
-
var form = $(this).closest('form')[0];
var yiiform = $("#" + form.id);
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]'] = [
- 'Ð\9aомменÑ\82аÑ\80ий могÑ\83Ñ\82 пиÑ\81аÑ\82Ñ\8c Ñ\82олÑ\8cко: ' + allowedCommentUsers.join(', ')
+ 'Ð\9aомменÑ\82аÑ\80ий могÑ\83Ñ\82 заполнÑ\8fÑ\82Ñ\8c Ñ\82олÑ\8cко: ' + 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])) {
}
}
+ console.log('Собранные ошибки для alert:', allErrors);
+
alert(allErrors.join('\n'));
} else {
yiiform.off('submit');
}
})
.fail(function () {
- console.log("Ð\9dе удалось выполнить запрос к серверу");
+ console.log("не удалось выполнить запрос к серверу");
});
return false;
}
});
- $('.messages').html(messages.join(', <br>'));
+ var strOut2 = messages.join(', <br>');
+ $('.messages').html(strOut2);
}
});
\ No newline at end of file