Welcome, Guest
Username: Password: Remember me

TOPIC: Enumeration Field with Multiselect

Enumeration Field with Multiselect 07 Jul 2016 08:27 #14174

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 112
  • Thank you received: 19
  • Karma: 8
Hi,

Is it possible to select multiple values within a simple Enumeration field?

Perhaps the multiple values would be stored in a single table record as comma delimited?
Just call me Chris :)
The administrator has disabled public write access.

Enumeration Field with Multiselect 07 Jul 2016 10:15 #14176

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 289
  • Thank you received: 124
  • Karma: 48
Nope.

An enumeration filed corresponds with the mysql enum field, it can only have 1 value.
The administrator has disabled public write access.
The following user(s) said Thank You: organicwebs

Enumeration Field with Multiselect 25 Jul 2016 11:07 #14322

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 112
  • Thank you received: 19
  • Karma: 8
Perhaps this post should be moved to "New functionalities"

What I proposed would have one value. The multiple values could be stored in a single table record as comma delimited (or choose your deliminator).

I need to create a form with ~10 multi-selected fields (with, say, 4 options). Creating 10 tables for this purpose is a little crazy - and then loading all these tables with basic data after every install is also crazy.

For now I will have to create ~40 Boolean fields to do this. :whistle:

No rush for me, I can get by for now.

Cheers
Just call me Chris :)
The administrator has disabled public write access.

Enumeration Field with Multiselect 25 Jul 2016 13:03 #14324

  • vlemos
  • vlemos's Avatar
  • Offline
  • Elite Member
  • Posts: 276
  • Thank you received: 38
  • Karma: 20
Hello Chris

Sounds as if you can use a single cook JSON field to achieve what you are working on (see below).
{
  "options": {
    "Apples": "yes",
    "Oranges": "yes",
    "Cherries": "no",
    "Cranberries": "yes",
    "Strawberries": "yes",
    "Watermelon": "no"
  }
}


You can then convert it to and object and code your interface to update its properties.
if (!empty($item->options) && is_string($item->options))
{
	$registry = new JRegistry;
	$registry->loadString($item->options);
	$item->options = $registry->toObject();
}

Good luck
vlemos
The administrator has disabled public write access.
The following user(s) said Thank You: organicwebs

Enumeration Field with Multiselect 25 Jul 2016 19:44 #14326

  • MorganL
  • MorganL's Avatar
  • Offline
  • Platinum Member
  • Posts: 437
  • Thank you received: 53
  • Karma: 20
You can certainly do the JSON field, but would it not be better to use the rather awesome Joomla multi-select functionality

www.j-cook.pro/index.php/r/relations

This allows multiselects done pro style 1:n (on the above link scroll down to FORMS to see the finished article, multiselects with live searching for large tables

Better database design overall (IMO)
Morgan Leecy MCSE

Novell / Linux
PHP. MYSQL, Apache, node.js
Coldfusion, JQuery, HTML5
Joomla
The administrator has disabled public write access.
The following user(s) said Thank You: admin, organicwebs

Enumeration Field with Multiselect 25 Jul 2016 20:31 #14329

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 289
  • Thank you received: 124
  • Karma: 48
When using a select field to parse the json, you will also have the mulitiselects, because cook uses chosen on select fields.
Personally I think that an enumeration field should be what it is, directly mapped to the enum mysql field, allowing just 1 value :)
The administrator has disabled public write access.

Enumeration Field with Multiselect 25 Jul 2016 21:07 #14332

  • vlemos
  • vlemos's Avatar
  • Offline
  • Elite Member
  • Posts: 276
  • Thank you received: 38
  • Karma: 20
I agree Morgan, less coding + less effort = no brainer = brilliant. . . .
The administrator has disabled public write access.

Field with Multiselect 16 Aug 2016 11:28 #14446

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 112
  • Thank you received: 19
  • Karma: 8
Thankyou for the suggestions and your time.

OK - forget my reference to the term "Enumeration". Maybe a new data type/wizard is needed.

The JSON field is not filterable - correct? I need that so the user can search for both "Apples" and "Oranges" - but not "Strawberries".

To use relational tables, for every Multi-selection field I would need to create 2 additional tables - correct? (Have I been doing this wrong?)

I would have to ask the user to populate these multi-selection tables. This not so good if there is custom code looking for specific values.

Example. Say, its a New Car ordering form. (I'm building something else - but just for simplicity...).

In a table "Car"...
  • "Options" column - values to be multi-selectable "Window Tint", "Towball", "Roof rack"
  • "Radio" column - values to be multi-selectable "FM" "AM" "CD" "USB" Bluetooth"
  • "Drive" column - values to be multi-selectable "Front Wheel Drive", "4WD", "Rear Wheel Drive" (my car is both 4WD and Rear).
  • "Airbags " column - values to be multi-selectable "Driver" "Passenger", "Side"

These are not large tables.

The developer defines these values in the JCook Builder. The Dealer fills in the car data. The Buyer searches the data to find the car they want.

Say there is more functionally - like a banner add pops up for Bluetooth devices when the user is searching for a car with "Bluetooth". So the Developer needs to hard set these values.

Creating a single table for these 4 basic multi selection fields is neat and simple. Creating 9 tables (if I understand relational tables correctly) is nuts.

For now, to do this I'm using Boolean data type. So instead of 4 Multi selections, I'm creating 14 Boolean.

Filtering is required. So if an end user is looking for "Bluetooth", they can find cars with Bluetooth.
(I don't think manually editing JASON to achieve the multi-select will achieve this)
Just call me Chris :)
Last Edit: 16 Aug 2016 11:30 by organicwebs. Reason: change title
The administrator has disabled public write access.

Field with Multiselect 16 Aug 2016 16:40 #14455

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 289
  • Thank you received: 124
  • Karma: 48
Yes, you have to add 2 tables, but you can fill them in the builder and then check "include dataset" so the user does not have to enter it but still has the flexibility to edit.
If you do not want the user to be able to edit, you can fork the model in such a way that editing/adding is only allowed for super-users (or another user)

I also think custom code should never need hard coded values, there is almost always a generic solution :)

But as with all: you can build it anyway you want with Cook!
The administrator has disabled public write access.
The following user(s) said Thank You: organicwebs
Time to create page: 0.070 seconds

Get Started