Multi Select Check Box?

Find out how to get things done with Servoy. Post how YOU get things done with Servoy

Multi Select Check Box?

Postby john1598360627 » Sat Sep 21, 2024 3:30 am

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.
john1598360627
 
Posts: 191
Joined: Tue Aug 25, 2020 3:03 pm

Re: Multi Select Check Box?

Postby swingman » Mon Sep 23, 2024 7:29 pm

Hi John,

I have never used the Choice Group: Checkbox.

There is an older checkbox component which you can assign a value list to and it will return an array of values...
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1479
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: Multi Select Check Box?

Postby john1598360627 » Tue Sep 24, 2024 11:33 pm

swingman wrote:Hi John,

I have never used the Choice Group: Checkbox.

There is an older checkbox component which you can assign a value list to and it will return an array of values...


Hmmm, does such a component still exist though? Checking the normal Checkbox component, it doesn't seem to have a valuelist.

Whatever way of doing that in the current version of Servoy, I'd like to know.
john1598360627
 
Posts: 191
Joined: Tue Aug 25, 2020 3:03 pm

Re: Multi Select Check Box?

Postby mboegem » Thu Sep 26, 2024 12:16 pm

Hi John,

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:
Code: Select all
var myArray = myVar.split('\n')


If you want to set first and last value set it like this:
Code: Select all
myVar = ['Yes', 'Maybe'].join('\n')


Hope this helps
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1817
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: Multi Select Check Box?

Postby swingman » Thu Sep 26, 2024 7:57 pm

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.
Christian Batchelor
Certified Servoy Developer
Batchelor Associates Ltd, London, UK
http://www.batchelorassociates.co.uk

http://www.postgresql.org - The world's most advanced open source database.
User avatar
swingman
 
Posts: 1479
Joined: Wed Oct 01, 2003 10:20 am
Location: London

Re: Multi Select Check Box?

Postby john1598360627 » Thu Sep 26, 2024 10:49 pm

mboegem wrote:Hi John,

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:
Code: Select all
var myArray = myVar.split('\n')


If you want to set first and last value set it like this:
Code: Select all
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
 
Posts: 191
Joined: Tue Aug 25, 2020 3:03 pm

Re: Multi Select Check Box?

Postby mboegem » Fri Sep 27, 2024 9:02 am

john1598360627 wrote: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 wrote: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 ;-))
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1817
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam


Return to How To

Who is online

Users browsing this forum: No registered users and 2 guests