PROBLEM
I want to setup a multi-select checkbox, in which when multiple checkboxes are selected that it returns an array of values.
I tried to do this with the Choice Group: Checkbox type. However, it only works when there’s one value selected. If multiple values get selected it bugs out and doesn’t display. It also seems to only return one value in the ‘onDataChange’ rather than multiple selected values.
HELP
Is there an element in Servoy that can display an Array of ‘selected’ items within a Valuelist? If the Choice Group: Checkbox can’t do this is there another element?
Feel like I’m missing something to enable this functionality.
Choice Group works for me, but maybe your expecting the wrong result.
My situation: Choice Group linked to form variable (type text), linked to valuelist with values ‘Yes’, ‘No’, ‘Maybe’
If you have multiple items selected, then the result is a text string containing: ‘Yes\nNo\nMaybe’ (so each value on a separate line)
In case you want to turn this into an array, use this:
var myArray = myVar.split('\n')
If you want to set first and last value set it like this:
In My Developer, 2023.03 (NG1), I have a section of components called ‘Servoy Default’, there is one called ‘Check’ in there.
Not sure if it will be available on NG2.
Choice Group works for me, but maybe your expecting the wrong result.
My situation: Choice Group linked to form variable (type text), linked to valuelist with values ‘Yes’, ‘No’, ‘Maybe’
If you have multiple items selected, then the result is a text string containing: ‘Yes\nNo\nMaybe’ (so each value on a separate line)
In case you want to turn this into an array, use this:
var myArray = myVar.split('\n')
If you want to set first and last value set it like this:
myVar = ['Yes', 'Maybe'].join('\n')
Hope this helps
Ahhhh okay so it stores it as a pseudo-array. A string with ‘\n’. Got it, yeah that fixed it.
Actually, in my case I had a database value that was already a pseudo-array but it was split up in a different way. Thus, I have to convert String to Array back to String.
Thanks for letting me know how exactly the component stored it.
john1598360627:
Ahhhh okay so it stores it as a pseudo-array. A string with ‘\n’. Got it, yeah that fixed it.
Great!
As far as I can recall, components which can return multiple values are always stored this way.
In these cases, it helps to temporarily use a textarea to display the same dataprovider, that will give you a better idea of the real value returned by the component
swingman:
In My Developer, 2023.03 (NG1), I have a section of components called ‘Servoy Default’, there is one called ‘Check’ in there.
Not sure if it will be available on NG2.
I believe it is supported, but hidden by default.
In general I find it easier to work with the new web components, also feels more prepared for future changes. (hopefully )