Try our conversational search powered by Generative AI!

Episerver Forms - add Css class field to base form element

Vote:
 

Currently there's no way to customize look and feel of single form element.

It would be nice to have a text field to input css class which will be rendered when rendering form element so we can do css customization

#208055
Oct 11, 2019 14:16
Vote:
 

You could put your own version of the FormContainerBlock in ~/Views/Shared/ElementBlocks with the extra css class that you need? And disable the defaultForms stylesheet if you need to as well in Form.config in ~/modules\_protected\EPiServer.Forms. Won't that give you enough customization options?

#208057
Oct 11, 2019 15:03
Vote:
 

You're partially right, but what I want to do is to customize chosen fields of my form, let's say "Last name" (text input) field needs to be red and "Sex" (select box) field needs to be green. Then I need to:

  • create my own classes, one extending TextElementBlock, second extending SelectionElementBlock adding "css class" field to both of them (I need to set it somewhere in Edit Mode)
  • create my own views in  ~/Views/Shared/ElementBlocks and copy existing markup of TextElementBlock.ascx and SelectionElementBlock.ascx just to add class="<%: formElement.cssClass %>"

I see some serious issues here: 

I need to create N new classes for each field type, I have to create N new views for each field type copying markup from base views. Now, when EpiServer decides to change anything in their base views/model - I'm screwed. 

IMHO: it's very basic need to be able to set CSS class to a form element (and actually a form container as well) and I was pretty surprised when I didn't find an option to do so

#208061
Oct 11, 2019 15:16
This thread is locked and should be used for reference only.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.