Детали
@@ -79,7 +82,7 @@
$('#sum').val(sum.toFixed(2));
}
- $('.deleteDetail').click(function () {
+ $(document).on('click', '.deleteDetail', function () {
var row = $(this).closest('tr');
row.remove();
updateSum();
@@ -96,34 +99,69 @@
var detailName = selectedDetail.text();
var detailCost = selectedDetail.data('cost');
+ var exists = false;
+ $('#detailsTable tbody tr').each(function () {
+ if ($(this).data('detail-id') == detailId) {
+ exists = true;
+ return false;
+ }
+ });
+
+ if (exists) {
+ alert('Эта деталь уже добавлена.');
+ return;
+ }
+
var newRow = `
${detailName}
|
- |
+ |
${detailCost} |
|
`;
$('#detailsTable tbody').append(newRow);
- $('.deleteDetail').off('click').on('click', function () {
- var row = $(this).closest('tr');
- row.remove();
- updateSum();
- });
-
- $('.detail-count').off('change').on('change', function () {
- updateSum();
- });
-
+ updateSum();
$('#detailSelect').val('');
} else {
alert('Выберите деталь для добавления');
}
});
+
+ $('#productForm').submit(function (event) {
+ var title = $('#title').val();
+ var isValid = true;
+
+ $('#titleError').text('');
+ if (title.length < 2 || title.length > 50) {
+ $('#titleError').text('Название должно быть от 2 до 50 символов.');
+ isValid = false;
+ }
+
+ var totalDetails = $('#detailsTable tbody tr').length;
+ if (totalDetails == 0) {
+ alert('Пожалуйста, добавьте хотя бы одну деталь.');
+ isValid = false;
+ }
+
+ $('#detailsTable tbody tr').each(function () {
+ var count = $(this).find('input[name="counts"]').val();
+ if (count < 1) {
+ alert('Количество каждой детали должно быть не менее 1.');
+ isValid = false;
+ return false;
+ }
+ });
+
+ if (!isValid) {
+ event.preventDefault();
+ }
+ });
+
updateSum();
});
diff --git a/Course/ImplementerApp/Views/Home/CreateProduction.cshtml b/Course/ImplementerApp/Views/Home/CreateProduction.cshtml
index 01e5847..bb64739 100644
--- a/Course/ImplementerApp/Views/Home/CreateProduction.cshtml
+++ b/Course/ImplementerApp/Views/Home/CreateProduction.cshtml
@@ -9,10 +9,13 @@
Создание производства
-
diff --git a/Course/ImplementerApp/Views/Home/IndexProduct.cshtml b/Course/ImplementerApp/Views/Home/IndexProduct.cshtml
index 97ac210..c75d75f 100644
--- a/Course/ImplementerApp/Views/Home/IndexProduct.cshtml
+++ b/Course/ImplementerApp/Views/Home/IndexProduct.cshtml
@@ -32,6 +32,9 @@