diff --git a/nuxt4-app/app/components/UbicacionMultiSelector.vue b/nuxt4-app/app/components/UbicacionMultiSelector.vue index 071d7a3..1ad2c2e 100644 --- a/nuxt4-app/app/components/UbicacionMultiSelector.vue +++ b/nuxt4-app/app/components/UbicacionMultiSelector.vue @@ -4,6 +4,7 @@ () const emit = defineEmits<{ @@ -72,24 +74,43 @@ const emit = defineEmits<{ // State const searchQuery = ref('') +// Computed - Normalize ubicaciones to InputMenuItem format +const normalizedUbicaciones = computed((): InputMenuItem[] => { + if (!Array.isArray(props.ubicaciones)) return [] + + return props.ubicaciones + .filter(u => u) // Filter out null/undefined + .map(u => { + // If it's already an object with label and value, use it + if (typeof u === 'object' && u.label && u.value) { + return { label: u.label, value: u.value } + } + // If it's a string, use it as both label and value + if (typeof u === 'string') { + return { label: u, value: u } + } + return null + }) + .filter((u): u is InputMenuItem => u !== null) +}) + // Computed - Get selected ubicaciones as objects for InputMenu const selectedUbicacionesObjects = computed(() => { - return props.ubicaciones.filter(u => props.selectedUbicaciones.includes(u.value)) + return normalizedUbicaciones.value.filter(u => + props.selectedUbicaciones.includes(u.value as string) + ) }) // Computed - Filter items based on search const filteredItems = computed((): InputMenuItem[] => { const query = searchQuery.value.trim().toLowerCase() - // Filter out undefined/null items and ensure they have label and value - const validUbicaciones = props.ubicaciones.filter(u => u && u.label && u.value) - if (!query) { - return validUbicaciones + return normalizedUbicaciones.value } - return validUbicaciones.filter(u => - u.label.toLowerCase().includes(query) + return normalizedUbicaciones.value.filter(u => + u.label && typeof u.label === 'string' && u.label.toLowerCase().includes(query) ) })