#Custom validation with HTML

19 messages · Page 1 of 1 (latest)

versed sierra
#

Is it possible to use links in validation?

fallen forgeBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

versed sierra
#
$fail(__('The cumulative percentage is higher than 100% <a href="#">Some link here</a>');
#

Custom validation with HTML

final granite
#

Not sure but something you can try:

$fail(new HtmlString(__('...')));
versed sierra
#

I tried this, it will just output the HTML 😦

final granite
#

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
versed sierra
#

I'm using the Filament Admin Panel where i have a custom validation for a Select. @final granite

final granite
#

Ok, makes sense. So maybe one option would be to show a custom error message in a View component... are you familiar with that?

versed sierra
#

I have done it before in Laravel itself, but not sure how i would do it in Filament Panel 🤔

final granite
#

Yes, I think your approach is correct but the only issue is the HTML doesn't work in the validation error message...

versed sierra
#

So you said you would solve it via a view?

final granite
#

It's a workaround. Basically I'm trying to think of a way for you to display your custom HTML.

versed sierra
#

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 🤣

final granite
#

Hehe. I feel like there's a way, just I can't quite remember. I'm sure I did it in the past 😵‍💫

versed sierra
#

Hmmm