fix: add double-submit protection for pricelist creation\n\n- Added isCreatingPricelist flag to prevent duplicate submissions\n- Disable submit button during creation process\n- Show loading text during submission\n- Re-enable button and restore text in finally block\n- Prevents accidental creation of duplicate pricelists
This commit is contained in:
@@ -220,6 +220,7 @@ let sortField = 'popularity_score';
|
|||||||
let sortDir = 'desc';
|
let sortDir = 'desc';
|
||||||
let pricelistsPage = 1;
|
let pricelistsPage = 1;
|
||||||
let pricelistsCanWrite = false;
|
let pricelistsCanWrite = false;
|
||||||
|
let isCreatingPricelist = false;
|
||||||
|
|
||||||
async function loadTab(tab) {
|
async function loadTab(tab) {
|
||||||
currentTab = tab;
|
currentTab = tab;
|
||||||
@@ -1055,6 +1056,13 @@ async function deletePricelist(id) {
|
|||||||
document.getElementById('pricelists-create-form').addEventListener('submit', async function(e) {
|
document.getElementById('pricelists-create-form').addEventListener('submit', async function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
|
if (isCreatingPricelist) return; // protection from double-submit
|
||||||
|
isCreatingPricelist = true;
|
||||||
|
|
||||||
|
const submitBtn = this.querySelector('button[type="submit"]');
|
||||||
|
submitBtn.disabled = true;
|
||||||
|
submitBtn.textContent = 'Создание...';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const pl = await createPricelist();
|
const pl = await createPricelist();
|
||||||
closePricelistsCreateModal();
|
closePricelistsCreateModal();
|
||||||
@@ -1062,6 +1070,10 @@ document.getElementById('pricelists-create-form').addEventListener('submit', asy
|
|||||||
loadPricelists(1);
|
loadPricelists(1);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
showToast('Ошибка: ' + e.message, 'error');
|
showToast('Ошибка: ' + e.message, 'error');
|
||||||
|
} finally {
|
||||||
|
isCreatingPricelist = false;
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
submitBtn.textContent = 'Создать';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user