Adding validation messages in afterStateUpdated hook for inputs
What I am trying to do:
I am trying to run validation logic that needs to run a query to detect if something else is using a specific provided identifier from a
live TextInput, and add error messages if it runs into issues. I do not want it to only show on form submission, I want it to update (debounced) as input is changed.
What I did:
I tried throwing a ValidationException::withMessages() with data.the_key and mountedActionData.the_key in afterStateUpdated.
I tried doing a $livewire->addError('the_key', 'The error message').
My issue/the error:
None of the above are adding errors reactively, as I would expect it to.
Code:
4 Replies
why not just make custom rule? i think its just the same. if the required() / visible() is false then the validation from the custom rule will not fire
I want it to run on every state change though, and validation doesn't run on state changes, only on submission
ok got it

Is what mine renders as, it's inside a table action
And doing
$livewire->addError('mountedActions.0.data.vendor_id', 'Testing'); does nothing either inside afterStateUpdated