F
Filamentβ€’6mo ago
PANC

Change form validation on custom action click.

Hey everyone. Like the title says. I have a form that has some validations but i want to bypass them if i click on a custom action button. EX: I have a simple form with some required fields and if i click "submit" it should check the validation but if i click "Save as draft" only the username is required. How can i do this?
Solution:
Was able to solve this on the custom "createDraft" function using the livewire $this->validate and passing only the new rules. Thank you πŸ™‚...
Jump to solution
2 Replies
toeknee
toekneeβ€’6mo ago
You would have a select as a draft/published etc and have closures on the required function for each field to only be required if !== 'DRAFT' for example. If you want a seperate button, save as draft.. you will need a custom save function which gets the raw state opposed to $this->getState and then only validate on the username.
Solution
PANC
PANCβ€’6mo ago
Was able to solve this on the custom "createDraft" function using the livewire $this->validate and passing only the new rules. Thank you πŸ™‚