mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Merge branch 'dev/presupuestos_guardar_event' into 'main'
Dev/presupuestos guardar event See merge request jjimenez/safekat!145
This commit is contained in:
@ -87,7 +87,7 @@
|
||||
},
|
||||
delay: 60,
|
||||
processResults: function(response) {
|
||||
yeniden(response. <?= csrf_token() ?> );
|
||||
yeniden(response.<?= csrf_token() ?>);
|
||||
return {
|
||||
results: response.menu
|
||||
};
|
||||
@ -111,6 +111,69 @@
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
|
||||
<!------------------------------------------------------->
|
||||
<!-- Código JS para detectar cambios en el presupuesto -->
|
||||
<!------------------------------------------------------->
|
||||
<?= $this->section("additionalInlineJs") ?>
|
||||
|
||||
// Obtener todos los campos de entrada del formulario
|
||||
const formInputs = document.querySelectorAll('input, textarea, select');
|
||||
|
||||
//console.log(formInputs)
|
||||
|
||||
// Crear un objeto para almacenar los valores originales
|
||||
const originalValues = {};
|
||||
|
||||
// Guardar los valores originales
|
||||
formInputs.forEach(function(input) {
|
||||
if (input.type === 'checkbox') {
|
||||
originalValues[input.id] = input.checked;
|
||||
} else {
|
||||
originalValues[input.id] = input.tagName.toLowerCase() === 'select'
|
||||
? $(input).val() // jQuery para obtener el valor de un select2
|
||||
: input.value;
|
||||
}
|
||||
});
|
||||
|
||||
console.log(originalValues)
|
||||
|
||||
// Agregar un evento de cambio a cada campo de entrada
|
||||
formInputs.forEach(function(input) {
|
||||
if (input.tagName.toLowerCase() === 'select' && $(input).data('select2')) {
|
||||
// Para elementos select2
|
||||
$(input).on('change', function() {
|
||||
verificarCambios();
|
||||
});
|
||||
} else {
|
||||
// Para otros tipos de campos
|
||||
input.addEventListener('input', function() {
|
||||
verificarCambios();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function verificarCambios() {
|
||||
// Verificar si hay cambios con respecto a los originales
|
||||
var cambiosDetectados = Array.from(formInputs).some(function(input) {
|
||||
return input.type === 'checkbox'
|
||||
? input.checked !== originalValues[input.id]
|
||||
: input.tagName.toLowerCase() === 'select'
|
||||
? $(input).val() !== originalValues[input.id]
|
||||
: input.value !== originalValues[input.id];
|
||||
});
|
||||
|
||||
// Mostrar alerta solo si hay cambios
|
||||
if (cambiosDetectados) {
|
||||
showBreadCrumbSaveButton(true);
|
||||
}else{
|
||||
showBreadCrumbSaveButton(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
<?= $this->endSection() ?>
|
||||
|
||||
<!------------------------------------------->
|
||||
<!-- Acciones antes de submit... -->
|
||||
<!------------------------------------------->
|
||||
|
||||
Reference in New Issue
Block a user