Skip Navigation

[Gelöst] Conditional fields and conditional css

Dieser Thread wurde gelöst. Hier ist eine Beschreibung des Problems und der Lösung.

Problem:
The user wanted to style a div based on the value of a custom field

Solution:
User code has some errors. Check the solution here https://toolset.com/forums/topic/conditional-fields-and-conditional-css/#post-1582341

Relevant Documentation:

- https://toolset.com/documentation/legacy-features/views-plugin/conditional-html-output-in-views/

- https://www.w3schools.com/cssref/sel_class.asp

This support ticket is created vor 4 Jahre, 1 Monat. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

Dieses Thema enthält 2 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von samuelH vor 4 Jahre, 1 Monat.

Assistiert von: Jamal.

Author
Artikel
#1582289
Skjermbilde 2020-04-11 kl. 15.54.10.png

Hi,
I have a conditional field, that I would like to change the backround color of depending on the conditional value.

I have put in this code:

<div class="q-gray1">
Status: [types field='statusbeskrivelse'][/types]

<div class="status">[wpv-conditional if="( $(wpcf-statusbeskrivelse) eq '2' )"]status-red[/wpv-conditional] [wpv-conditional if="( $(wpcf-statusbeskrivelse) eq '1' )"]status-gronn[/wpv-conditional]</div></div>

And this CSS
status-red {background-color: red;}
status-gronn {background-color: green;}

The conditional field shows the text value, but are not changing the background color. Where am I doing wrong here?

The field should show the value of the condition (This works), but not the words "status-gronn" The background if the field should turn green.

#1582341

Jamal
Supporter

Sprachen: Englisch (English ) Französisch (Français )

Zeitzone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

I think that both your view and CSS codes are not correct. The CSS code should use (.) before the class name. Then the name should be used inside the class attribute of your div tag. Try the following:
1. CSS

.status-red {background-color: red;}
.status-gronn {background-color: green;}

2. View:

<div class="q-gray1">
Status: [types field='statusbeskrivelse'][/types]

<div class="status [wpv-conditional if="( $(wpcf-statusbeskrivelse) eq '2' )"]status-red[/wpv-conditional] [wpv-conditional if="( $(wpcf-statusbeskrivelse) eq '1' )"]status-gronn[/wpv-conditional]">[wpv-conditional if="( $(wpcf-statusbeskrivelse) eq '2' )"]status-red[/wpv-conditional] [wpv-conditional if="( $(wpcf-statusbeskrivelse) eq '1' )"]status-gronn[/wpv-conditional]</div></div>

Read more about the class CSS selector here versteckter Link

#1582787

My issue is resolved now. Thank you!

Dieses Ticket ist jetzt geschlossen. Wenn Sie ein Toolset Kunde sind und Hilfe benötigen, eröffnen Sie bitte ein neues Support-Ticket.