Hi,
I have a checkboxes field with about 25 checkboxes for the user to select. I'd like to be able to do 2 things:
1) Output just first checkbox that the user has selected
2) Output one random checkbox that the user has selected
I thought this might work for 1) but it doesn't:
[types field='ambiance' index='0'][/types]
Thank you for your assistance.
Tim
This will only work if you edit the ShortCode manually or write some Custom Code to do that.
With Toolset you can display Checkboxes in different ways, no matter if in a Single Post or in a Views Loop.
You need at least Types and Views for this.
1. Display the value of this field from the database
This will display what is saved for the field. Note that fields can either save nothing or 0 when they are not checked.
Usually checked values will be "1" unless set differently in Toolset > Post Fields.
[types field='toolset-cehckboxes' option='0'][/types]
[types field='toolset-cehckboxes' option='1'][/types]
[types field='toolset-cehckboxes' option='2'][/types]
With this you can already control what part of the field to display (you could as example omit the first option)
2. Display all values with a separator
This is basically the same as #1, you just control the separator.
3. Enter values for 'selected' and 'not selected' states
You will enter values to display for each checkbox of the checkboxes and for each case (checked or not).
[types field='toolset-cehckboxes' option='0' state='checked']sel[/types]
[types field='toolset-cehckboxes' option='0' state='unchecked']not sel[/types]
[types field='toolset-cehckboxes' option='1' state='checked']empty[/types]
[types field='toolset-cehckboxes' option='1' state='unchecked']etc[/types]
[types field='toolset-cehckboxes' option='2' state='checked'][/types]
[types field='toolset-cehckboxes' option='2' state='unchecked'][/types]
These are the only methods to address the items in a checkboxes field.
Or, if you write custom code.
Checkboxes are complex arrays of arrays (of arrays).
Hence, I suggest to look at some examples how you can access those values with Custom Code:
https://pastebin.com/wz6dQVBE > line 21 onwards deals with checkboxes.
Unfortunately it is not possible to loop through the Checkboxes like through a posts list.