$this->form->getState() without firing validations?

Is it possible to get the data using ->getState() without triggering the validation? I want to implement a save draft feature, that is why.
Solution:
$this->form->getRawState()
Jump to solution
7 Replies
Patrick Boivin
@vahnmarty You can read the unvalidated data from $this->data (on a resource page) On a custom form, it'll be as individual properties on the component class or what you have in getFormStatePath()
Solution
LeandroFerreira
$this->form->getRawState()
benzo
benzo17mo ago
Any ideas on how to deal with file inputs ? $this->form->getRawState() for an input file gives back a Livewire\TemporaryUploadedFileobject, the file stays is in the livewire-tmp folder. In case of a "save as draft" feature, the file should be validated ( size format etc.. ) and moved from the tmp folder as it is wiped every day. Maybe in a draft folder and not the definitive one?
awcodes
awcodes17mo ago
Just save the record as you normally would and use a Status field on the record for draft, published, etc.
benzo
benzo17mo ago
Yes I thought about it. But when having mandatory fields, you can not solve this with statuses: Example: a post with a title and an image. Title is mandatory. The goal is to be able to upload an image and save it as a draft, without a title. In this case, you should be able to bypass the required validation for title until you save it definitively. Don't know if it makes sense but I have to deal with a form with a lot of mandatory inputs where sometimes users do not have all the information when they have to fill it.
Patrick Boivin
Patrick Boivin17mo ago
You can have dynamic validation rules... make the title required only if the status is published
benzo
benzo17mo ago
Ah nice! I will have to work with an intermediate status or updateQuietly the model as the published status could fired an event. This will also remove the red (*) mandatory label indicator on draft status but I'll give it a try! ->required(true && !this->draft) This works perfectly, solution was right in front of me! Thanks @pboivin
Want results from more Discord servers?
Add your server