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.

Data Model Questions

Comma in Enum() value


Reply

8 Posts   782 Views

Avatar
Spambanjo

4 September 2012 at 8:31pm (Last edited: 10 January 2013 12:01am), Community Member, 15 Posts

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

Avatar
martimiz

6 September 2012 at 11:23pm Forum Moderator, 1091 Posts

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

6 September 2012 at 11:31pm Community Member, 15 Posts

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

Avatar
swaiba

8 September 2012 at 2:41am Forum Moderator, 1796 Posts

@martimiz & @Spambanjo

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

Avatar
martimiz

8 September 2012 at 5:02am Forum Moderator, 1091 Posts

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

9 September 2012 at 2:45am Community Member, 244 Posts

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

Avatar
Spambanjo

11 September 2012 at 8:58pm Community Member, 15 Posts

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

11 September 2012 at 10:36pm (Last edited: 11 September 2012 10:38pm), Forum Moderator, 1091 Posts

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 :-) )