How to dispatch event when validation has error on current locale?

Hello, I made a component and when I use methods such as ‘required()’ in this component, I get an error due to invisible components. How can I get past this? As a solution, I want to check the validation process in the background and if there is an error in the relevant language, I want to return it to the language with dispatch error in Livewire. How can I do it?
4 Replies
Matthew
Matthew4w ago
https://filamentphp.com/docs/3.x/forms/validation#other-rules https://laravel.com/docs/11.x/validation#custom-validation-rules You can dispatch an event when validation fails, like this
TextInput::make('slug')->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if ($value === 'foo') {
$this->dispatch('event-name');
}
},
])
TextInput::make('slug')->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if ($value === 'foo') {
$this->dispatch('event-name');
}
},
])
Azad Furkan ŞAKAR
Thank you for your reply, i already check documentation but i don't get it yet how can i solve this problem. I think main problem is other language components not visible when i submit form. That's why its throw error i guess. I am about to make a plugin, so i have to do it automatically for every component has required, url etc. methods.
Matthew
Matthew4w ago
Can you share the code? Then we can help you better There is very little
Azad Furkan ŞAKAR
It's going to be paid plugin, that's why i can't share now :/

Did you find this page helpful?