Fix: categorías en add.html desde api/categorias.php con manejo de error visible
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
e98bfa0afb
commit
d2aa3d92c4
+17
-7
@@ -13,17 +13,27 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
// Default a hoy
|
// Default a hoy
|
||||||
iptFecha.valueAsDate = new Date();
|
iptFecha.valueAsDate = new Date();
|
||||||
|
|
||||||
// Cargar categorías desde la API
|
// Cargar categorías
|
||||||
apiFetch('api/movimientos.php')
|
cargarCategorias();
|
||||||
.then(r => r ? r.json() : Promise.reject('no-auth'))
|
|
||||||
.then(data => {
|
async function cargarCategorias() {
|
||||||
if (!data || !data.categorias) return;
|
|
||||||
const sel = document.getElementById('ui-categoria');
|
const sel = document.getElementById('ui-categoria');
|
||||||
|
try {
|
||||||
|
const r = await apiFetch('api/categorias.php');
|
||||||
|
if (!r) return; // redirigió a login
|
||||||
|
const data = await r.json();
|
||||||
|
if (!data.categorias?.length) {
|
||||||
|
sel.innerHTML = '<option value="">Sin categorías</option>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
sel.innerHTML = data.categorias.map(c =>
|
sel.innerHTML = data.categorias.map(c =>
|
||||||
`<option value="${c.id}">${c.nombre}</option>`
|
`<option value="${c.id}">${c.nombre}</option>`
|
||||||
).join('');
|
).join('');
|
||||||
})
|
} catch (e) {
|
||||||
.catch(() => {});
|
console.error('Error cargando categorías:', e);
|
||||||
|
sel.innerHTML = '<option value="">Error al cargar</option>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tipo selector
|
// Tipo selector
|
||||||
const updateTipoUI = () => {
|
const updateTipoUI = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user