Closed aerni closed 2 years ago
I get your point and now this pain point myself 😊
I am not sure if the livewire integration is the right place to fetch errors from the error bag, as this belongs to Antlers and is not related to Livewire only. Does this make sense or am I missing something?
I was contemplating the same. I think it goes into the same direction like Erin's idea here: https://github.com/statamic/ideas/issues/75
The only issue with Erin's implementation is, that Livewire's error bag can't be accessed with the session()
. At least in my testing, it didn't work. I had to get the error bag directly from the Livewire instance. And if that's the case, I think getting the error from the Livewire instance would be in line with this addon's purpose of making Livewire accessible with Antlers.
Here's my implementation with a custom tag: https://github.com/aerni/statamic-livewire-forms/blob/main/src/Tags/LivewireForms.php
How have you been handling errors in Antlers?
Here is an very old PR from myself: https://github.com/statamic/cms/pull/2333
Do you suggest rolling with my own error tag until this idea is implemented? Or are you open for a PR?
I did a little tinkering and would love to include an error-tag. So yes, a PR would be appreciated a lot.
What would you think about the following syntax:
{{ errors }}
to get the complete bag
{{ error:name }}
to fetch a specific error.
What I am not sure about, as I haven't looked into it: The best way to get the errors into the view. I would think that the livewire errors already are there, but that we only need to pass them to the view.
Awesome! I like the idea to get the whole bag or specific error.
Unfortunately, the {{ errors }}
tag name won't work. I'm using this tag name in my Statamic Livewire Forms addon and it's causing issues with password protected pages. Check this issue: https://github.com/statamic/cms/issues/4004
Long story short; we have to settle on a different tag name. Or maybe you see something I don't?
Hmmm ... I see.
We can think about this a little longer, but what about {{ error:all }}
for now?
Personally, I'd probably try to scope the tag name to this addon to not cause any potential name conflicts. It's not as pretty but more bulletproof.
Either {{ livewire:errors }}
or {{ livewire_errors }}
You mentioned: {{ error:name }}
to fetch a specific error.
What's the use case of fetching a specific error? The following already works in Antlers:
{{ if error }}
{{ error }}
{{ /if }}
Might this release solve the issue? I haven't checked it yet.
I just tested the Statamic PR and it solves this issue.
There is currently no way to get validation errors with Antlers. With Blade you can easily do the following:
I'm currently using a custom tag to get around this. But I was wondering if you are open to a PR that adds the functionality to this package. It could work like this: