Hi,
we populate an optionsfield with dynamic values like in this article: https://formidableforms.com/knowledgebase/frm_setup_new_fields_vars/#kb-populate-a-field-with-wordpress-posts
That works.
Now we would like to add dynamic classes to each option. We tried the following, which doesn't work:
$values['class'][$p->ID] = 'myClass';
Is there a way to add a specific class to each select value?
Thank you in advance
Sebastian
You can add classes to $values['classes']. The classes are applied to the field container. However, please keep in mind that the level of customization may vary across different browsers. Some properties may not be supported or may have limited effects on select options. It's always a good practice to test your styles across different browsers to ensure consistent behavior.
Hi Victor,
thank you for your help. I will try it with 'classes' instead of 'class'. Good to know.
I found another solution with jQuery to add specific classes that worked. I look for the content of the selectoption and add the class this way.
<script>
(function($){
$("select option:contains('Natur')").addClass("natur");
$("select option:contains('Mensch')").addClass("mensch");
$("select option:contains('Sprache')").addClass("sprache");
$("select option:contains('Gesundheit')").addClass("gesundheit");
$("select option:contains('Gestaltung')").addClass("gestaltung");
})(jQuery);
</script>
Please login or Register to submit your answer