How to add asterisk to every required field label?

bernhard
Member | 31
+
0
-

Hello everybody!

$form->addText('foo', 'My foo field')
  ->setRequired();

How can I have the “My foo field” appear as “My foo field*”?

…No, I don't want to add the asterisk by hand in the label. I want to add it programmatically in my renderer to every field that is required, but I can't manage to make it work :(

Thx for your help!

Last edited by bernhard (2022-03-10 18:04)

David Grudl
Nette Core | 7790
+
+1
-

It depends on what HTML code you generate, but it goes something like this:

.required th label:after { content: '\a0*'; }
Rick Strafy
Nette Blogger | 41
+
0
-

Hi, if you have your own renderer, look how to add that class at https://github.com/…Renderer.php#L84

And then you can do it with css .required label:after { content: “*”; }