mirror of
https://github.com/Matewoo/pdf-writer.git
synced 2026-11-18 18:52:45 +01:00
fix bug with manual saving english translation
This commit is contained in:
@@ -701,35 +701,33 @@ function displayTranslation(translationText, originalDishes = []) {
|
|||||||
saveBtn.style.borderRadius = '4px';
|
saveBtn.style.borderRadius = '4px';
|
||||||
saveBtn.style.cursor = 'pointer';
|
saveBtn.style.cursor = 'pointer';
|
||||||
saveBtn.onclick = async () => {
|
saveBtn.onclick = async () => {
|
||||||
// Get all translated texts from form fields using the same logic as the PDF button
|
// Get all translated texts from form fields
|
||||||
const updatedTranslations = [];
|
const updatedTranslations = [];
|
||||||
const inputs = form.querySelectorAll('input:not([type="hidden"])');
|
const dishContainers = form.querySelectorAll('.dish-container');
|
||||||
const hiddenInputs = form.querySelectorAll('input[type="hidden"]');
|
|
||||||
let hiddenIndex = 0;
|
|
||||||
|
|
||||||
for (let i = 0; i < inputs.length; i++) {
|
// Process each dish container separately
|
||||||
const mainCourse = inputs[i].value;
|
dishContainers.forEach(container => {
|
||||||
let sideDish = '';
|
const inputs = container.querySelectorAll('input');
|
||||||
|
const hasHiddenInput = container.querySelector('input[type="hidden"]') !== null;
|
||||||
|
|
||||||
// If this is a soup (has hidden input), use empty side dish
|
// This is a soup item (with hidden input)
|
||||||
if (hiddenInputs[hiddenIndex] &&
|
if (hasHiddenInput) {
|
||||||
hiddenInputs[hiddenIndex].parentNode === inputs[i].parentNode) {
|
const mainCourse = inputs[0].value; // First input is main course (soup)
|
||||||
sideDish = '';
|
updatedTranslations.push({
|
||||||
hiddenIndex++;
|
main_course: mainCourse,
|
||||||
i++; // Skip the next input which would be the hidden one
|
side_dish: '' // Soups have no side dish
|
||||||
} else {
|
});
|
||||||
// Otherwise get the next input as side dish
|
|
||||||
i++;
|
|
||||||
if (i < inputs.length) {
|
|
||||||
sideDish = inputs[i].value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// This is a regular dish
|
||||||
updatedTranslations.push({
|
else {
|
||||||
main_course: mainCourse,
|
const mainCourse = inputs[0].value;
|
||||||
side_dish: sideDish
|
const sideDish = inputs[1].value;
|
||||||
});
|
updatedTranslations.push({
|
||||||
}
|
main_course: mainCourse,
|
||||||
|
side_dish: sideDish
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Save the translations to the database
|
// Save the translations to the database
|
||||||
const saveResult = await saveTranslationsToDatabase(updatedTranslations, originalDishes);
|
const saveResult = await saveTranslationsToDatabase(updatedTranslations, originalDishes);
|
||||||
|
|||||||
Reference in New Issue
Block a user