Forums / Developer / DataType: Matrix with fixed values

DataType: Matrix with fixed values

Author Message

Albe Terra

Thursday 24 July 2008 1:50:58 am

Hi!
I need to create a class with a particular datatype. I need to manage information from a matrix, where I want to fix the possible values.

The idea is to have a table with "Regions" and "Cities". During the creation of a new instance of the class the user will select a Region from a small set of values, and as a consequence the city (from the set of cities of the selected Region).

Is it possible to obtain this result with eZMatrix? Or with object relations?

Thanks, Albe

Robert Ledoux

Monday 04 August 2008 10:05:30 am

Hello

have you find a soution for this problem :
http://ez.no/developer/forum/developer/datatype_matrix_with_fixed_values

thanks for your answer.

chap

Gabriel Finkelstein

Monday 04 August 2008 4:07:22 pm

You could make 2 classes: Region and City. Each City has an object relation with a Region. You store regions and cities in 2 different folders. And in the edit template of your class, you add an objectrelation for region and another for city.
Both relation input fields should be dropdowns. The "Region" dropdown:

<select name="region" onchange="changeCities(this.options[this.selectedIndex].value)">
{foreach $regions as $region}
   <option value={$region.id}>{$region.name}</option>
{/foreach}
</select>

The "City" dropdown:

<select name="city">
{foreach $cities as $city}
   <option value={$city.id} region={$city.data_map.region.content.id}>{$city.name}</option>
{/foreach}
</select>

Or something like that. And then make a javascript function called changeCities(), which hides the cities from the dropdown, that don't belong to the selected region.

Of course, there's no kind of validation, so a user could actually pick a region and a city that doesn't belong to that region.

Maybe there's some kind of "Related Dropdowns" datatype somewhere.

Albe Terra

Tuesday 05 August 2008 7:04:32 am

Thanks a lot!
I will try with this solution!

If other solutions come to your mind, please tell me :)

Thanks again for your help,
Albe!

Piotrek Karaƛ

Tuesday 05 August 2008 11:49:40 am

With little effort, you can make a custom datatype operate on any custom data model (db table set), so if you do not need the regions/cities to be objects, you could backup Gabriel's idea with some lightweight 1:n db tables, and even provide UI for managing those tables in the administration interface. That would then work as one coherent attribute of a class.

--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu