fix: cache-busting + validazione conf + reset form prodotto

- Aggiunto version param a CSS/JS per forzare reload browser
- startManualEntry() resetta pf-conf-size-row correttamente
- Validazione: se unit=conf ma dimensione non specificata, errore
- onAddUnitChange: scrollIntoView quando conf-size-row appare
- Reset campi conf quando si cambia unità nel form aggiungi
This commit is contained in:
dadaloop82
2026-03-11 15:54:20 +00:00
parent bf2e137502
commit e6a9fb06a7
3 changed files with 27 additions and 4 deletions
+25 -2
View File
@@ -1535,6 +1535,12 @@ function startManualEntry(barcode = '') {
document.getElementById('pf-image-preview').style.display = 'none';
document.getElementById('product-form-title').textContent = 'Nuovo Prodotto';
// Reset conf-size-row visibility
const pfConfRow = document.getElementById('pf-conf-size-row');
if (pfConfRow) pfConfRow.style.display = 'none';
document.getElementById('pf-conf-size').value = '';
document.getElementById('pf-conf-unit').value = 'g';
// Reset manual-edit tracking flags
document.getElementById('pf-category').dataset.manuallySet = 'false';
document.getElementById('pf-defqty').dataset.manuallySet = 'false';
@@ -2198,16 +2204,22 @@ function onAddUnitChange() {
// Show/hide conf size row
const confRow = document.getElementById('add-conf-size-row');
if (confRow) {
confRow.style.display = unit === 'conf' ? 'block' : 'none';
const isConf = unit === 'conf';
confRow.style.display = isConf ? 'block' : 'none';
// Pre-fill from currentProduct if available
if (unit === 'conf' && currentProduct) {
if (isConf && currentProduct) {
const sizeInput = document.getElementById('add-conf-size');
const unitSelect = document.getElementById('add-conf-unit');
if (currentProduct.package_unit && currentProduct.default_quantity > 1) {
sizeInput.value = currentProduct.default_quantity;
unitSelect.value = currentProduct.package_unit;
} else {
sizeInput.value = '';
unitSelect.value = 'g';
}
}
// Scroll into view so the user sees the new field
if (isConf) setTimeout(() => confRow.scrollIntoView({ behavior: 'smooth', block: 'nearest' }), 100);
}
// If switching units, suggest a sensible quantity
@@ -2338,6 +2350,17 @@ async function submitAdd(e) {
const selectedUnit = document.getElementById('add-unit').value;
const productUnit = currentProduct.unit || 'pz';
// Validate conf fields
if (selectedUnit === 'conf') {
const confSize = parseFloat(document.getElementById('add-conf-size')?.value);
if (!confSize || confSize <= 0) {
showLoading(false);
showToast('Specifica il contenuto di ogni confezione', 'error');
document.getElementById('add-conf-size')?.focus();
return;
}
}
const result = await api('inventory_add', {}, 'POST', {
product_id: currentProduct.id,
quantity: parseFloat(document.getElementById('add-quantity').value) || 1,
BIN
View File
Binary file not shown.
+2 -2
View File
@@ -9,7 +9,7 @@
<title>🏠 Dispensa Manager</title>
<link rel="manifest" href="manifest.json">
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🏠</text></svg>">
<link rel="stylesheet" href="assets/css/style.css">
<link rel="stylesheet" href="assets/css/style.css?v=20260311b">
<!-- QuaggaJS for barcode scanning -->
<script src="https://cdn.jsdelivr.net/npm/@ericblade/quagga2@1.8.4/dist/quagga.min.js"></script>
</head>
@@ -750,6 +750,6 @@
<div class="modal-content" id="modal-content" onclick="event.stopPropagation()"></div>
</div>
<script src="assets/js/app.js"></script>
<script src="assets/js/app.js?v=20260311b"></script>
</body>
</html>