• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Return checkbox item labels to other list

enrb

Member
Good morning,
in a list I have an element that I called COLOR of type checkbox (where the values are 1, 2, 3, ... while the labels are: white, pink, red, ...)

In another list I wanted to create an element that would give me the labels (white, pink, red) if the id of the first list and the second list matched.
I have tried with a query inserted in a calc element, but I can only see the values (1, 2, 3) and not the labels.

The query I use is this:

Code:
$mydb = JFactory::getDBO();
$mydb->setQuery(" SELECT mytable.color FROM mytable WHERE mytable.id = '{rowid}' ");
$rows = $mydb->loadObjectList();

$myhtml = "";
foreach ($rows as $row) {
   $myhtml .= $row->color." ";
}
return $myhtml;


Is it possible to view the labels?

Thanks a lot to everyone!
 
When you check the database, you can see that checkbox element values are stored as ["1"] etc. Labels are in Fabrik element database table somewhere in a params json string.

Here are a few options:

1) Have a separate list for colors where you have the id and color name (label) field. And then in your other list, use databasejoin element referring to Colors list and rendered as checkbox. In that case you can select the "label" element from your Colors table instead of id.

2) Use color name also for value in your checkbox element (e.g. value and label both "white").

3) If you have just a few colors and they are pretty static, you can use "CASE" in your query, like:
Code:
$mydb->setQuery("SELECT
CASE WHEN color = '1' THEN 'White'
WHEN color = '2' THEN 'Pink'
WHEN color = '3' THEN 'Red'
END AS color
FROM mytable WHERE id = '{rowid}' ");
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top