validateOnly checks the rules, but requires a 'Submit' action to show the outcome.
Hiya! I'm trying to leverage validateOnly after a custom action which checks the validity of some data. I'm able to use ->rules([]) to define what these rules are, but I'm forced to hit 'submit' in order to have the validation messages populate.
Is there another way to force the validation message to show up on demand?
Solution:Jump to solution
No, I followed that process. That works in the case of the field validation itself. But if the field does not change, then there is no reason for the TextInput afterStateUpdated hook to be called.
Instead, as it's calling an Action, if you want to force validation and have it behave properly, it would appear you need to call callAfterStateUpdated() on the Component from within the after() method on the Action.
```php...
6 Replies
Does your input have
live()
?Yep
I’ll double check via debugging that after state updated is being called, because technically, as the value in the field isn’t changing (the action takes the information and validates it based on the external APi) maybe it isn’t firing the validateOnly - although I was pretty sure I checked that.
What would be the best case: if failed verification, validation error invoked and visible straight away. If successful, it’s marked as such with a visual representation that the data was good (I wonder if a suffix icon could be used and switched? How do you interact with an input other than just setting its value via Set? Is that even possible?
I've at least forced it to run the validate message by calling $component->callAfterStateUpdated() from within the action, which fires off the validation - but the rule breakage is reflected as a thrown exception rather than being presented in the validation messages (per the screenshot).
I think the issue may actually be that the afterStateUpdated hook is occurring before the action returns and i'm able to set the appropriate data, so for that period, the data is valid. (which is why when calling callAfterStateUpdated() manually it does produce the right error, but it's not caught by the wrapper in order to present it as a validation message, rather a thrown exception.
Maybe this will help https://laraveldaily.com/post/filament-validate-one-form-field-live-before-submit
Solution
No, I followed that process. That works in the case of the field validation itself. But if the field does not change, then there is no reason for the TextInput afterStateUpdated hook to be called.
Instead, as it's calling an Action, if you want to force validation and have it behave properly, it would appear you need to call callAfterStateUpdated() on the Component from within the after() method on the Action.