Skip to content

Bootstrap 4 Form Theme: Explain way to add asterisk to required field #14915

Closed
@ThomasLandauer

Description

@ThomasLandauer

Since form errors are rendered inside the <label>, it's not possible to add the common red asterisk (to indicate a required field) in the "usual" way:

label.required:after { content:"*"; color:red; }

... cause when a form error is present, the result looks like this:

Your name
ERROR
*

... instead of:

Your name *
ERROR

So what's the best way of doing it??

In Symfony 5.1, you can use label_html in the FormType, see https://symfony.com/doc/current/reference/forms/types/form.html#label-html

->add('name', TextType::class, ['label' => 'Your name <strong>*</strong>', 'label_html' => true])

So if there's no better/other way, I'd suggest to explain this at https://symfony.com/doc/current/form/bootstrap4.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions