Help with Multiple Select Searchable Component #918
-
How to handle data received from a multiple select searchable? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Do you feel like there is something missing in our documentation of multi-selects in https://sql-page.com/component.sql?component=form ? Can you give more insights on what you are trying to do, what you have tried already, and where you have encountered issues ? This is the example from the documentation page about handling the data received from a multi-select field: insert into best_fruits(id) -- INSERT INTO ... SELECT ... runs the SELECT query and inserts the results into the table
select CAST(value AS integer) as id -- all values are transmitted by the browser as strings
from json_each($my_field); -- in SQLite, json_each returns a table with a "value" column for each element in the JSON array |
Beta Was this translation helpful? Give feedback.
-
I created a select searchable multiple, but when I send it through the form, it only gives me the value of the last selected item. |
Beta Was this translation helpful? Give feedback.
-
Can you give a reproduction ? Maybe share a minimal reproduction of your issue as sql files |
Beta Was this translation helpful? Give feedback.
-
This is the select: SELECT
'adicionais' as name,
'select' as type,
'Adicionais' as label,
'Selecione os adicionais' as empty_option,
(
SELECT
JSON_ARRAYAGG(JSON_OBJECT(
'value', id,
'label', CONCAT(descricao, ' (R$', CAST(valor AS CHAR), ')')
))
FROM
tb_opcoes
WHERE
tipo = 'A'
) as options,
4 as width,
TRUE as searchable,
TRUE as multiple,
FALSE as required; And this is the code I am using to receive the selected items: SELECT 'json' as component;
SELECT :adicionais; The result: [
{"CAST(? AS CHAR)":"2"}
] |
Beta Was this translation helpful? Give feedback.
-
I should probably improve the wording and the examples, but this is the important part of the documentation that you may have missed:
In your case, what this means is you should have SELECT
'adicionais[]' as name,
... |
Beta Was this translation helpful? Give feedback.
-
True, I ended up forgetting that I should pass [] (brackets), sorry for my lack of attention. Sorry for making you waste your time with this! |
Beta Was this translation helpful? Give feedback.
I should probably improve the wording and the examples, but this is the important part of the documentation that you may have missed:
In your case, what this means is you should have