Update static/script.js
Browse files- static/script.js +6 -5
static/script.js
CHANGED
|
@@ -818,6 +818,7 @@ async function hienThiHSKH() {
|
|
| 818 |
]
|
| 819 |
});
|
| 820 |
|
|
|
|
| 821 |
$("#bangHSKH tbody").on("input", "input, textarea, select", function () {
|
| 822 |
const lastRow = $("#bangHSKH tbody tr").last();
|
| 823 |
let isEmpty = true;
|
|
@@ -832,7 +833,7 @@ async function hienThiHSKH() {
|
|
| 832 |
if (!isEmpty) {
|
| 833 |
const newRow = lastRow.clone();
|
| 834 |
|
| 835 |
-
// ✅ Tính STT
|
| 836 |
const currentSTTs = $("#bangHSKH tbody tr").map(function () {
|
| 837 |
const val = parseInt($(this).find("td").eq(0).text().trim(), 10);
|
| 838 |
return isNaN(val) ? 0 : val;
|
|
@@ -840,18 +841,18 @@ async function hienThiHSKH() {
|
|
| 840 |
const maxSTT = Math.max(...currentSTTs);
|
| 841 |
newRow.find("td").eq(0).text(maxSTT + 1);
|
| 842 |
|
| 843 |
-
// ✅ Tính số PYC
|
| 844 |
const currentPYC = $("#bangHSKH tbody tr").map(function () {
|
| 845 |
const pycText = $(this).find("td").eq(1).text().trim();
|
| 846 |
-
const match = pycText.match(/(\d{2}\/
|
| 847 |
if (match) return parseInt(match[2], 10);
|
| 848 |
return 0;
|
| 849 |
}).get();
|
| 850 |
const maxPYC = Math.max(...currentPYC);
|
| 851 |
-
const newPYC = `25/
|
| 852 |
newRow.find("td").eq(1).text(newPYC);
|
| 853 |
|
| 854 |
-
// ✅ Reset dữ liệu
|
| 855 |
newRow.find("input[type='text']").val("");
|
| 856 |
newRow.find("textarea").val("");
|
| 857 |
newRow.find("select").val("");
|
|
|
|
| 818 |
]
|
| 819 |
});
|
| 820 |
|
| 821 |
+
// === Tự động thêm dòng mới khi dòng cuối có thay đổi ===
|
| 822 |
$("#bangHSKH tbody").on("input", "input, textarea, select", function () {
|
| 823 |
const lastRow = $("#bangHSKH tbody tr").last();
|
| 824 |
let isEmpty = true;
|
|
|
|
| 833 |
if (!isEmpty) {
|
| 834 |
const newRow = lastRow.clone();
|
| 835 |
|
| 836 |
+
// ✅ Tính STT lớn nhất hiện có
|
| 837 |
const currentSTTs = $("#bangHSKH tbody tr").map(function () {
|
| 838 |
const val = parseInt($(this).find("td").eq(0).text().trim(), 10);
|
| 839 |
return isNaN(val) ? 0 : val;
|
|
|
|
| 841 |
const maxSTT = Math.max(...currentSTTs);
|
| 842 |
newRow.find("td").eq(0).text(maxSTT + 1);
|
| 843 |
|
| 844 |
+
// ✅ Tính số PYC lớn nhất hiện có
|
| 845 |
const currentPYC = $("#bangHSKH tbody tr").map(function () {
|
| 846 |
const pycText = $(this).find("td").eq(1).text().trim();
|
| 847 |
+
const match = pycText.match(/(\d{2}\/DL6\/)(\d{4})$/i);
|
| 848 |
if (match) return parseInt(match[2], 10);
|
| 849 |
return 0;
|
| 850 |
}).get();
|
| 851 |
const maxPYC = Math.max(...currentPYC);
|
| 852 |
+
const newPYC = `25/DL6/${(maxPYC + 1).toString().padStart(4, "0")}`;
|
| 853 |
newRow.find("td").eq(1).text(newPYC);
|
| 854 |
|
| 855 |
+
// ✅ Reset dữ liệu nội dung các ô còn lại
|
| 856 |
newRow.find("input[type='text']").val("");
|
| 857 |
newRow.find("textarea").val("");
|
| 858 |
newRow.find("select").val("");
|