$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.7 Replies
@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
$this->form->getRawState()
Any ideas on how to deal with file inputs ?
$this->form->getRawState()
for an input file gives back a Livewire\TemporaryUploadedFile
object, 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?Just save the record as you normally would and use a Status field on the record for draft, published, etc.
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.
You can have dynamic validation rules... make the title required only if the status is
published
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