Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Comma in Enum() value


Go to End


9 Posts   4174 Views

Avatar
Spambanjo

Community Member, 24 Posts

4 September 2012 at 8:31pm

Edited: 31/10/2014 4:15am

Hi all,

I have a list of values for my Enum() field which has an option containing a comma. Unfortunately, due to accuracy of information on the site, I do not have the option to re-word this option.

Can anyone tell me how to escape commas in the Enum() values?

Thanks in advance.

EDIT: This is for Silverstripe 2.4.7

EDIT2: Here is the solution for Silverstripe 3. I have no tested this in 2 as I no longer use it.

'Income' => "Enum(array('Under £20,000','£20,000-£29,999','£30,000-£39,999','$40,000 and over'))"

Avatar
martimiz

Forum Moderator, 1391 Posts

6 September 2012 at 11:23pm

Hi, welcome to the forums,

I've never tried this, but you should be able to use an array of values instead of a comma separated list. So maybe you can sneak in the comma that way...

Avatar
Spambanjo

Community Member, 24 Posts

6 September 2012 at 11:31pm

Hmmm, I did not know that. I'll give it a shot, thank you!

Avatar
swaiba

Forum Moderator, 1899 Posts

8 September 2012 at 2:41am

@martimiz & @Spambanjo

would be very interested if this is possible - I asked and Willr said it wasn't a while back...

Avatar
martimiz

Forum Moderator, 1391 Posts

8 September 2012 at 5:02am

I looked at the Enum code in 3.0 - it explodes the list to an array, unless it is already an array. So that should be ok. Don't really know what happens with the array when the field is created. Hence the slight hesitation. Easily testable though...

Avatar
ajshort

Community Member, 244 Posts

9 September 2012 at 2:45am

You can do something like "Enum(array('First Value', 'Second Value'))"

Avatar
Spambanjo

Community Member, 24 Posts

11 September 2012 at 8:58pm

Hi, sorry for my lack of input on this thread, I've been doing a different job and haven't had time to test this yet. I will reply as soon as I have a chance to test this

I also apologise if this thread is in the wrong place, but this was actually a question for Silverstripe 2.4

Avatar
martimiz

Forum Moderator, 1391 Posts

11 September 2012 at 10:36pm

Edited: 11/09/2012 10:38pm

Code for 2.4.7 looks about the same, so that should work as well...

And sure, this is the right place, there are no separate forums for 3.0 or 2.4. This can be confusing, because of the major differences in both versions, so people: please mention your version. (just taking the opportunity to mention this :-) )

Go to Top