Jump to content
Alejandro

Including unselected field options in field output

Recommended Posts

Alejandro

A while back someone asked if he could include, in addition to the selected options fora field, also the unselected ones, but with a different styling. I came up with a solution using the PHP formatting setting in the custom field so I am sharing it here in case someone else finds it useful.

$options = $DB->setQuery('
    SELECT 
        FieldOption.text
    FROM 
        #__jreviews_fields AS Field
    LEFT JOIN
        #__jreviews_fieldoptions AS FieldOption ON Field.fieldid = FieldOption.fieldid
    WHERE 
        Field.name = "'.$field['name'].'"
    ORDER BY
        FieldOption.text ASC
')->loadColumn();

$selected = array();
foreach ($output AS $key=>$val)
{
    $selected[strip_tags($val)] = $val;
}
$newOutput = array();
$selectedKeys = array_keys($selected);
foreach ($options AS $key=>$val)
{
    if (in_array(strip_tags($val), $selectedKeys)) {
        $options[$key] = $selected[strip_tags($val)];
    }
    else {
        $options[$key] = sprintf('<span class="jrUnselectedOption">%s</span>',$val);
    }
}
return array_values($options);

The unselected options will be wrapped in the span with the "jrUnselectedOption" CSS class so you can style that whichever way you want.

Share this post


Link to post
www.HDsports.at

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Edited by www.HDsports.at

Share this post


Link to post
Alejandro

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
www.HDsports.at

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
Alejandro

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post
www.HDsports.at

This section is only visible with a valid subscription. If you have a valid subscription, please login.

Share this post


Link to post

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Please refer to our Privacy Policy.