Forums / Setup & design / Enum multiple choice changes to single choice on update

Enum multiple choice changes to single choice on update

Author Message

J Jones

Sunday 05 August 2007 5:08:30 pm

I am new to EZ Publish and have been working with it for a few weeks.

I created a new user class for our members. In the registration form I wanted them to be able to make multiple choices for certain attributes. Since I wanted the choices displayed as checkboxes it seemed that <i>enum</i> was the sole datatype that could be used.

Using EZ Selection with multiple choice would both display as an ugly box, and also complicating for users needing to ctrl + click to make selections.

Then I found out that enum was deprecated. But it still seemed to work out fine using 3.9 so I didn't care. Today I was just about to csv-import all my users, when I realized that all of a sudden the registration form had radio buttons rather than check boxes?

I soon realized that when I edit my class the box I ticked for 'multiple choice' is suddenly unmarked, then saving it results in the obvious change on the site.

Also, the test users that I had added and choosing multiple values for these questions using enum did no longer have multiple data stored for them...

Luckily enough I hadn't imported the users yet and not put the site live.

A word of wisdom, don't use enum. I am now looking into other solutions to use eZSelection but displaying checkboxes instead. This post looks promising - http://ez.no/community/forum/developer/how_to_create_multi_checkbox_like_multi_option/re_how_to_create_multi_checkbox_like_multi_opt__7

Jesper

Heath

Sunday 05 August 2007 5:14:11 pm

Hello,

The enum datatype is deprecated and has been for a very long time (since before 3.6). Some say it's slow while others have reported it as simply buggy and inaccurate in real use.

I've seen and tracked a (unreported) bug in production of a very old 3.4 site back in 2005 where it was simply inaccurate causing inaccuracies in production use where it just did not work as advertised/documented just before it was deprecated.

I think it would be most wise to <i>stop</i> using it for your production eZ Publish web sites.

Consider using the 'selection' datatype instead or if that does not meet your needs create your own derivative datatype based on selection or the enhancedselection datatypes.

<i>"This datatype should not be used any more because it is slow. It has been substituted by the "Selection" datatype."</i> From: <i>http://ez.no/doc/ez_publish/technical_manual/3_9/reference/datatypes/enum</i>

References:
<i>http://www.google.com/search?q=Enum+site%3Aez.no+deprecated</i>

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

J Jones

Tuesday 07 August 2007 3:20:06 am

Hi Heath,

Many thanks for your input.

I did go with the solution mentioned in my previous post (custom made data types is too complicated, at least for me).

Unfortunately I ran into new problems. Mostly because in my templates I can't check if tha attribute has a value or not.

I have my own user class, with about 20 attributes. Most of them are text line, so on various pages I use something like

Location:
{if $:item.object.data_map.city.has_content}
{attribute_view_gui attribute=$:item.object.data_map.city},
{/if}

Previously for enum-datatype I used

<p><strong>{'Organisation - geographic outreach'|i18n('design/standard/user/register')}:</strong><br />
	{foreach $user.contentobject.data_map.organisationoutreach.content.enumobject_list as $element}  
	{$element.enumelement}<br />
	{/foreach}</p>

.. which worked well.

But changing to the new data type i CAN'T retrieve the value.

A simple 'object.has.content' like above only returns <i>ezcontentclassattribute</i>. i tried with '$myobject(attribute(show)' in numerous variations but can't figure out how to do it from the result...

Any ideas,

Jesper

Heath

Tuesday 07 August 2007 3:56:58 am

Hello,

I may have encountered a similar issue in the past when trying to use a 'selection' like solution.

The follow code references are not tested or suited for any specific purpose .. just yet. Still, I believe that you may find code which you can use within them...

Take a long detailed look at the following (and all the rest of the related code within each contribution) for an example of the features you require.

First suggestion

http://projects.ez.no/bcstateselect
<i>http://svn.projects.ez.no/bcstateselect/trunk/extension/bcstateselect/design/standard/templates/content/datatype/collect/bcstateselect.tpl</i>

Second suggestion
http://projects.ez.no/informationcollectionformvalidation
<i>http://svn.projects.ez.no/informationcollectionformvalidation/trunk/extension/informationcollectionformvalidation/design/standard/override/templates/full/request_form.tpl</i>

I am fairly certain each of these contains examples of testing within a template if datatype / attribute has content and using the content.

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

J Jones

Thursday 09 August 2007 12:02:23 pm

Hi again,

Thanks for the links.

I ended up doing a quite simple approach by nesting two foreach-loops.

{foreach $user.contentobject.data_map.selection_array.class_content.options as $element}
          {foreach $user.contentobject.data_map.selection_array.content as $childelement}  
                    {if eq($element.id, $childelement)}
	            {$element.name}<br />
	    {/if}
         {/foreach}
{/foreach}

The first foreach gave me:

Attribute Type Value
0 array Array(2)
>id string 0
>name string 'Global'
1 array Array(2)
>id string 1
>name string 'Africa (Sub-Sahara)'
..etc

And the second one..

Attribute Type Value
0 string 1
1 string 5
2 string 7

So by nesting the foreach:es I managed to map them together.

Like the value 1 for the second foreach would correspond to the name 'Africa (Sub-Sahara)' and only write out the selected option values (1, 5 and 7).

It might not be the cleanest approach but it worked fine for me.

/Jesper