Validaciones - Alta de: Proveedores, Transportistas, Transportes y Choferes
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
<input type="hidden" name="id_transporte" value="<?= $t['id_transporte'] ?>">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Vehículo *</label>
|
||||
<label class="form-label">Contenedor *</label>
|
||||
<input name="vehiculo" id="vehEdit" class="form-control"
|
||||
value="<?= htmlspecialchars($t['vehiculo']) ?>" required>
|
||||
</div>
|
||||
@@ -82,28 +82,36 @@
|
||||
|
||||
<script>
|
||||
document.getElementById('formTransEdit').addEventListener('submit', function(e) {
|
||||
// Campos que validamos:
|
||||
const veh = document.getElementById('vehEdit').value.trim();
|
||||
const fisc = document.getElementById('fiscEdit').value.trim();
|
||||
const trans = document.getElementById('trEdit').value;
|
||||
const fotoF = document.getElementById('fotoEdit').files[0];
|
||||
|
||||
// Validaciones de campos obligatorios
|
||||
if (!veh) {
|
||||
e.preventDefault();
|
||||
return Swal.fire({ icon:'error', title:'Vehículo requerido', text:'Por favor ingresa el nombre del vehículo.' });
|
||||
Swal.fire({ icon:'error', title:'Vehículo requerido', text:'Por favor ingresa el nombre del vehículo.', confirmButtonColor: '#dc3545'});
|
||||
document.querySelector('input[name="veh"]').focus();
|
||||
return;
|
||||
}
|
||||
if (!fisc) {
|
||||
e.preventDefault();
|
||||
return Swal.fire({ icon:'error', title:'Identificador fiscal requerido', text:'Por favor ingresa el identificador fiscal.' });
|
||||
Swal.fire({ icon:'error', title:'Identificador fiscal requerido', text:'Por favor ingresa el identificador fiscal.', confirmButtonColor: '#dc3545' });
|
||||
document.querySelector('input[name="fisc"]').focus();
|
||||
return;
|
||||
}
|
||||
if (!trans) {
|
||||
e.preventDefault();
|
||||
return Swal.fire({ icon:'error', title:'Transportista no seleccionado', text:'Debes elegir un transportista.' });
|
||||
Swal.fire({ icon:'error', title:'Transportista no seleccionado', text:'Debes elegir un transportista.', confirmButtonColor: '#dc3545' });
|
||||
document.querySelector('input[name="trans"]').focus();
|
||||
return;
|
||||
}
|
||||
if (fotoF && fotoF.size > 2 * 1024 * 1024) {
|
||||
if (fotoF && fotoF.size > 2 * 1024 * 1024) { // 2 MB
|
||||
e.preventDefault();
|
||||
return Swal.fire({ icon:'error', title:'Foto demasiado grande', text:'La imagen no debe exceder 2 MB.' });
|
||||
}
|
||||
// Si todo OK, se envía
|
||||
// Si todas las validaciones pasan, el formulario se envía.
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user