Validation messages are not htmlable, but they output htmlable label values by default

When I create a TextInput field, I can make the label htmlable:
TextInput::make('column')
->label(fn() => new HtmlString('<span>Some text</span>'))
->required()
TextInput::make('column')
->label(fn() => new HtmlString('<span>Some text</span>'))
->required()
This is fine, however validation messages are currently not htmlable, and this leads to an undesired bug in the output of validation messages, see image. Is there a way to solve this? Right now it seems the only solution to this it to completely customise the validation messages, but this is unfeasible. Ideally, the validation message might either take the rendered label html, or would be htmlable too. Or is there some other way around this?
No description
Solution:
I just discovered ->validationAttribute(), which solves this by allowing you to independently define the attribute used in validation messages!!!
Jump to solution
4 Replies
toeknee
toeknee4w ago
Not that I know off?
morty
morty4w ago
Are you just trying to style the label with CSS and wrapping a span on it? If so, perhaps using extra html attributes and applying a class instead? https://filamentphp.com/docs/3.x/forms/fields/getting-started#adding-extra-html-attributes
rominronin
rominroninOP4w ago
Yes - that’s what we’ll have to do, thanks. But I still think there’s room for a code improvement above - if label() is htmlable, any markup will be be rendered raw in the validation message. So either another input attribute must be used for the validation placeholder, or htmlable must be removed. Right?
Solution
rominronin
rominronin3w ago
I just discovered ->validationAttribute(), which solves this by allowing you to independently define the attribute used in validation messages!!!

Did you find this page helpful?