haciendo vista de pagos

This commit is contained in:
2025-11-04 15:29:29 +01:00
parent 7516e9e91e
commit dc64e40e38
11 changed files with 186 additions and 6 deletions

View File

@ -422,7 +422,7 @@ $(() => {
return;
}
// Éxito real: cerrar y recargar tabla
modal.addClass('d-none');
$('#direccionFormModal').modal('hide');
seleccionarDireccionEnvio();
},
error: function (xhr) {
@ -432,7 +432,6 @@ $(() => {
const isEdit = $('#direccionFormModalBody #direccionForm input[name="_method"][value="PUT"]').length > 0;
const title = $('#direccionFormModalBody #direccionForm').data(isEdit ? 'edit' : 'add');
$('#direccionModal .modal-title').text(title);
initSelect2Cliente(true);
return;
}
// Fallback

View File

@ -153,10 +153,59 @@ $(() => {
$('#btn-checkout').prop('disabled', true);
});
$('input[name="paymentMethod"]').on('change', function() {
$('input[name="paymentMethod"]').on('change', function () {
const method = $(this).val();
// set the hidden input value in the form
$('input[name="method"]').val(method);
});
$(document).on("change", ".direccionFacturacion", function () {
const isChecked = $(this).is(':checked');
if (isChecked) {
$('.direccionFacturacionItems').removeClass('d-none');
} else {
$('.direccionFacturacionItems').addClass('d-none');
$('#razonSocial').val('');
$('#tipoIdentificacionFiscal').val('DNI');
$('#identificacionFiscal').val('');
}
});
$(document).on('submit', '#direccionForm', function (e) {
e.preventDefault();
const $form = $(this);
$.ajax({
url: $form.attr('action'),
type: 'POST', // PUT simulado via _method
data: $form.serialize(),
dataType: 'html',
success: function (html) {
// Si por cualquier motivo llega 200 con fragmento, lo insertamos igual
if (typeof html === 'string' && html.indexOf('id="direccionForm"') !== -1 && html.indexOf('<html') === -1) {
$('#direccionFormModalBody').html(html);
const isEdit = $('#direccionFormModalBody #direccionForm input[name="_method"][value="PUT"]').length > 0;
const title = $('#direccionFormModalBody #direccionForm').data(isEdit ? 'edit' : 'add');
$('#direccionModal .modal-title').text(title);
return;
}
// Éxito real: cerrar y recargar tabla
$('#direccionFormModal').modal('hide');
seleccionarDireccionEnvio();
},
error: function (xhr) {
// Con 422 devolvemos el fragmento con errores aquí
if (xhr.status === 422 && xhr.responseText) {
$('#direccionFormModalBody').html(xhr.responseText);
const isEdit = $('#direccionFormModalBody #direccionForm input[name="_method"][value="PUT"]').length > 0;
const title = $('#direccionFormModalBody #direccionForm').data(isEdit ? 'edit' : 'add');
$('#direccionModal .modal-title').text(title);
return;
}
// Fallback
$('#direccionFormModalBody').html('<div class="p-3 text-danger">Error inesperado.</div>');
}
});
});
});

View File

@ -181,7 +181,7 @@
});
// Submit del form en el modal
$(document).on('submit', '#direccionForm', function (e) {
$(document).on('submit', '#direccionForm', function (e) {
e.preventDefault();
const $form = $(this);

View File

@ -0,0 +1,3 @@
$(()=>{
})