Hi all,
I’m trying to dynamically update the options of a Select
component (subcategoriaFiltro
) based on the selected value from another Select
(categoriaFiltro
).
I wrote a JavaScript query like this:
const subcategoriasPorCategoria = {
"maquillaje": ["ojos", "labios", "rostro", "accesorios", "uñas"],
"cuidado de la piel": [
"Arrugas y Líneas Finas",
"Piel Grasosa",
"Resequedad",
"Piel Sensible",
"Manchas Oscuras",
"Imperfecciones",
"Piel Propensa al Acné"
],
"nutrición": [
"malteadas complete blend",
"matcha",
"cafés delish",
"suplementos nutriplus",
"recetario nutriplus",
"gummies"
],
"cuidado personal": [
"jabones",
"cuidado de manos y pies",
"gel de baño",
"cuidado bucal",
"fragancias",
"baño y cuidado corporal",
"protección solar",
"gel de masaje",
"aceites esenciales"
],
"cabello": [
"shampoo",
"acondicionadores y mascarillas capilares",
"aceites, sueros y aerosoles"
],
"hombres": [
"cuidado personal",
"fragancias"
]
};
// Get selected category
const categoriaSeleccionada = categoriaFiltro.value;
// Get corresponding subcategories
const subcategorias = subcategoriasPorCategoria[categoriaSeleccionada] || [];
// Assign to subcategoriaFiltro
subcategoriaFiltro.setOptions(subcategorias.map(sc => ({ label: sc, value: sc })));
But I get this error:
subcategoriaFiltro.setOptions is not a function
I assumed .setOptions()
would work based on other Retool examples, but it seems that may not apply here.
Any idea how I can update the options of one Select based on another?
Should I be using temporary state, or is there a more idiomatic Retool way to do this? I want this to happen automatically when the user changes the category selection.
Thanks in advance!
Edit:
I made two transformers, but the program's still not working. This is what I have so far: