Forum
Can i make an array of perch content checkboxes?
Hi there,
I've have multiple checkboxes that control the output of some text. So associated with a project is a skill set. For instance:
Design, Development.
A user can currently tick to output the text. I wanted to know - can I build an array of these options and then I can use a function to build a comma separated string. Would I simply need to give the inputs a common name and build the array that way?
My code thus far:
<p class="project__meta"><perch:content id="project__meta1" type="checkbox" label="Design" allowempty="true" required="false" suppress="true" value="Design"/>
<perch:if exists="project__meta1">
Design
</perch:if>
<perch:content id="project__meta2" type="checkbox" label="Developement" allowempty="true" required="false" suppress="true" value="Development" />
<perch:if exists="project__meta2">
Development
</perch:if>
<perch:content id="project__meta3" type="checkbox" label="Illustration" allowempty="true" required="false" suppress="true" value="Illustration" />
<perch:if exists="project__meta3">
Illustration
</perch:if>
<perch:content id="project__meta4" type="checkbox" label="Branding" allowempty="true" required="false" suppress="true" value="Branding" />
<perch:if exists="project__meta4">
Branding
</perch:if>
</p>
What you have there is probably the way to do it, unless you go down the route of using a category set.
Thanks Drew, The only limitation I've encountered is if I use something like:
.. means if I select say the 2nd, 3rd item, I still get the
·
from the ending 1st item (as the real desire was to separate them by middots). Perhaps I need to take a look at a category set!Hi Drew,
Thanks for the heads up on using categories. I managed to achieve the desired result by using categories and adjusting my templates.
You're a star!
Hi Mat,
You can do it like this:
I have stripped out a few tags that aren't necessary, e.g. perch:if isn't required if you don't use suppress="true", 'required is 'false' by default and 'allowempty' is 'true' by default for checkboxes.
I hope it helps.
Hi Simon,
Nice work. I ended up using categories as my template code then just needed:
Thanks though — I'm sure that'll come in handy sometime :)