F
Filamentβ€’15mo ago
BlackShadow

Custom validation with HTML

Is it possible to use links in validation?
13 Replies
BlackShadow
BlackShadowOPβ€’15mo ago
$fail(__('The cumulative percentage is higher than 100% <a href="#">Some link here</a>');
$fail(__('The cumulative percentage is higher than 100% <a href="#">Some link here</a>');
Patrick Boivin
Patrick Boivinβ€’15mo ago
Not sure but something you can try:
$fail(new HtmlString(__('...')));
$fail(new HtmlString(__('...')));
BlackShadow
BlackShadowOPβ€’15mo ago
I tried this, it will just output the HTML 😦
Patrick Boivin
Patrick Boivinβ€’15mo ago
Ok... this would have been too easy πŸ˜„ So I'm not sure how you would go about it correctly, but I think a workaround could be to just output a custom error message in this case, maybe something like this in your Blade template:
@error('my_field')
The cumulative percentage is higher than 100% <a href="#">Some link here</a>
@enderror
@error('my_field')
The cumulative percentage is higher than 100% <a href="#">Some link here</a>
@enderror
BlackShadow
BlackShadowOPβ€’15mo ago
I'm using the Filament Admin Panel where i have a custom validation for a Select. @pboivin
Patrick Boivin
Patrick Boivinβ€’15mo ago
Ok, makes sense. So maybe one option would be to show a custom error message in a View component... are you familiar with that?
BlackShadow
BlackShadowOPβ€’15mo ago
I have done it before in Laravel itself, but not sure how i would do it in Filament Panel πŸ€” Example what im currently doing:
Select::make('example')->rules(new CustomRuleExample), // php artisan make:rule CustomRuleExample
Select::make('example')->rules(new CustomRuleExample), // php artisan make:rule CustomRuleExample
https://laravel.com/docs/10.x/validation#using-rule-objects
Patrick Boivin
Patrick Boivinβ€’15mo ago
Yes, I think your approach is correct but the only issue is the HTML doesn't work in the validation error message...
BlackShadow
BlackShadowOPβ€’15mo ago
So you said you would solve it via a view?
Patrick Boivin
Patrick Boivinβ€’15mo ago
It's a workaround. Basically I'm trying to think of a way for you to display your custom HTML.
BlackShadow
BlackShadowOPβ€’15mo ago
I mean.. its not a big deal basically sometimes i give a validation error where i indicate what Customer is using something and then that customer name would be a link to the CustomerResource. I was just wondering if it could be done easily, but seems like its not how its meant to work 🀣
Patrick Boivin
Patrick Boivinβ€’15mo ago
Hehe. I feel like there's a way, just I can't quite remember. I'm sure I did it in the past πŸ˜΅β€πŸ’«
BlackShadow
BlackShadowOPβ€’15mo ago
Hmmm
Want results from more Discord servers?
Add your server