Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] Display Label of Enum Value

Display Label of Enum Value 23 Nov 2016 11:36 #14728

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 133
  • Thank you received: 21
  • Karma: 4
Hi Everyone,
From inside my forked grid view I would like to echo the Label of an Enum field (given its value). Essentually I am trying to create a grid column with the Enum Value displayed, but the Enum Label as hover text.

In my code below "Hello" needs to be replaced with the Enum Label. $row->validation just gives me the enum value.
<?php 
	$data = "<span class='hasPopover' data-content='Hello' data-placement='left'>".$row->validation."</span>";
	echo JDom::_('html.fly', array(
	'dataValue' => $data
));?>
On another generic question... is there a website about that explains JDom? What are the JDOM arguments/syntax? How do we actually modifiy it? Which folder it is stored? I find the JCook Docs on JDOM unclear.
Just call me Chris :)
Last Edit: 23 Nov 2016 11:37 by organicwebs.
The administrator has disabled public write access.

Display Label of Enum Value 23 Nov 2016 18:49 #14743

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
I am gonna work about the whole documentation of Cook this winter.

For getting the item of an enumeration, just get access to it with the index.
$list = XxxxHelperEnum::_('table_validation');
$item = $list[$row->validation];
$myLabel = $item['text'];

Or another way in line:
$myLabel = XxxxHelperEnum::_('table_validation')[$row->validation]['text'];

I think I should write some more code in the enumeration helper to access and work with the lists.
Getting the item by value
Getting the text

EDIT : It would had the advantage to handle basic errors because the code I give to you is raw. It do not prevents in case the value is empty, or the item not found in the list.
Coding is now a piece of cake
Last Edit: 23 Nov 2016 18:55 by admin.
The administrator has disabled public write access.

Display Label of Enum Value 23 Nov 2016 18:53 #14744

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Edited previous
Coding is now a piece of cake
The administrator has disabled public write access.

Display Label of Enum Value 23 Nov 2016 20:18 #14745

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
NEW UPGRADE

In the continuity of the enumerations feature, I modified the helper source code.
Now it is possible to achieve easily with :
$myLabel = XxxxHelperEnum::text('table_validation', $row->validation);

And for the whole item (array, not object):
$myItem = XxxxHelperEnum::item('table_validation', $row->validation);

The system is open for unlimited forks and now works in an instanced way. (Advanced customs)

I will explain widely all the code features in the documentations. For the moment, you can use easily for the basics.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: organicwebs

Display Label of Enum Value 24 Nov 2016 14:24 #14747

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 133
  • Thank you received: 21
  • Karma: 4
Thanks Chef!

I haven't got it working yet - it is returning nothing for me at the moment.

Regarding "table_validation" - is that the table name in which the enum is inside? For me, my "validation" enum field is inside a table called "devices" - so should that be "table_devices"?
Just call me Chris :)
The administrator has disabled public write access.

Display Label of Enum Value 24 Nov 2016 20:41 #14748

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Should be :
devices_validation

The function in the Helper is called '___devices_validation' and appears at the top of the class file.
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: organicwebs

Display Label of Enum Value 29 Nov 2016 02:44 #14762

  • organicwebs
  • organicwebs's Avatar
  • Offline
  • Premium Member
  • Chris
  • Posts: 133
  • Thank you received: 21
  • Karma: 4
Thanks Chef,
that make sence - I didn't try that :P

This works nicely for me in fork/views/devices/tmpl/default_grid.php ...
$myLabel = XxxxHelperEnum::_('devices_validation')[$row->validation]['text'];

But just so you know, this comes up empty for me ...
$myLabel = XxxxHelperEnum::text('devices_validation', $row->validation);
Just call me Chris :)
The administrator has disabled public write access.

Display Label of Enum Value 01 Dec 2016 01:28 #14789

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Should be better now.

Fixed.
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.111 seconds

Get Started