Forum
Select Box with Items That Have a Comma
Hi. So I'd like to give my client the option to select a date in a list that has a comma in it. The selected result will look like:
Monday, Sept 24
So in the perch:content, here's the issue:
<perch:content id="day-date" type="select" label="Day and Date"
options="Monday, Sept 24, Tuesday, Sept 25, Wednesday, Sept 26" allowempty="false" required>
Of course the comma in "Monday, Sept 24" is splitting this into two items. "Monday" and "Sept 24".
So is there a way to include a comma in this syntax without making two different selects?
yes there is...
\,
Escape the comma with a backslash...
Not sure about escaping commas in this. Not very compact but I think this will work
Wow... really Greg, I am not sure it can get easier then
Hello Leigh,
Escaping commas works for public facing forms on the site (i.e. using
perch:input
), but doesn't work for fields in the control panel.So Robert's approach works for
perch:input
in forms on the website. Greg's approach works forperch:content
(and other namespaces) in the control panel and Drew suggested the same approach here:https://forum.grabaperch.com/forum/01-19-2015-how-to-have-a-list-box-in-the-cms
Should you use either approach? I don't know what your use case is, but if you are dealing with dates, I would use the date field type instead:
https://docs.grabaperch.com/templates/field-types/date/
The
format
attribute allows you to format the output however you want it. Plus the template won't be outdated (you wouldn't have to update the template after Sept 26).p.s. You shouldn't use hyphens in your ID
id="day-date"
as they are not allowed. You can use underscores insteadid="day_date"
.Thanks for the help guys. Unfortunately, Greg's method didn't work, and Robert's doesn't apply for this case. I'm not using the date picker before the format of the date is just 4 days for an event. To reduce user error, I wanted to combine the dropdown. But backslashes don't work, the IF statements shown above don't work either. :(
Did you change the id to
id="day_date"
notid="day-date"
? The IF statements are working on my test setup.Yes I did. Oddly it's showing nothing.
If you change the ID, you need to save the edit form again.
Yep, I know.
I tried changing the ID's the non-matching ones, but that also did not work. Bazaar - I do this all the time and I don't see what's missing here.
Your above template is working fine for me.
What does
<perch:showall>
display?