Background color in function of the field's value

More
6 years 1 month ago - 6 years 1 month ago #72265 by ggppdk
Hello

First create the new layout file value_mycoloredlayout.php to the folder i mentioned above

Then find code
Code:
// Add prefix / suffix $field->{$prop}[$n] = $pretext . $value . $posttext;

Replace it with
Code:
// Value to color (array) map $value_to_color = array( '0' => 'darkorange', '1' => 'brown', '2' => 'darkgreen', '3' => 'darkcyan' ); $colored_value = isset($value_to_color[$value]) ? '<span class="badge" style="background-color: ' . $value_to_color[$value] . '">' . $value . '</span>' : '<span class="badge" style="background-color: gray;">' . $value . '</span>'; // Add prefix / suffix $field->{$prop}[$n] = $pretext . $colored_value . $posttext;

I have not tested the above code, i just took 5 minutes to write it


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...
Last edit: 6 years 1 month ago by ggppdk.

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72268 by erica
It's for a text field, but in my case it's a radio field. I anderstand the principe of fonctionnement but for the radio field the code php is more complexe
What I must replace ?

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago - 6 years 1 month ago #72271 by ggppdk
Hello
try this:

Find (note: Do not enable 'Show non-selected values' in field configuration):
Code:
$html[] = $pretext . $disp . $posttext;

Replace with
Code:
// Value to color (array) map $value_to_color = array( '0' => 'darkorange', '1' => 'brown', '2' => 'darkgreen', '3' => 'darkcyan' ); $colored_disp = isset($value_to_color[$element->value]) ? '<span class="badge" style="background-color: ' . $value_to_color[$element->value] . '">' . $disp . '</span>' : '<span class="badge" style="background-color: gray;">' . $disp . '</span>'; $html[] = $pretext . $colored_disp . $posttext;


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...
Last edit: 6 years 1 month ago by ggppdk.

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago - 6 years 1 month ago #72277 by erica
You are the best.
It's working.
Thanks a lot.
Last edit: 6 years 1 month ago by ggppdk.

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72279 by micker
if you want to do this can do it without php code ...
with prefix and suffix code that depend of your value and display

FLEXIcontent is Free but involves a very big effort on our part.
Like the our support? (for a bug-free FC, despite being huge extension) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing reviews. Thanks![/size]

Please Log in or Create an account to join the conversation.

More
6 years 1 month ago #72280 by erica
Thank you Micker for this information

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.313 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline