Using `getRawState()` returns an array for FileUpload
I use
getRawState()
in order to display previews within my blade view, but the only problem is that while getState()
returns the correct string and URL for a $logo value/state, using getRawState()
doesn't and causes issues. How would I fix this?16 Replies
That’s a tricky one. Not only does getState() run validation. It also processes file uploads. Seems like you’d have to either process the image manually or try to maybe create a temporary signed url maybe to be able to view the image since it has to be a publicly accessible path.
I'm sort of confused why
getState()
should run validation before a form is submitted? Like is that really the correct thing to do? Sorry I am just curious. But since the $logo doesn't react with the state of other fields I decided to do this but only for the $logo as an exception:
Let me know if you think doing this will be fine in this case, thanks!Validation should always run before a form’s data it persisted. So getState() just bundles all that functionality or validating and processing so the valid data can be passed to create or update. That’s why raw state exists, so you can intercept the process and do anything you need to do with it.
Okay understood. So does that mean calling
getState()
should return errors only when, for example, clearing the input in a required text field?It should only return errors if there are any validation errors on the form. By default it happens when you click the forms save / create button. But if you have live() on a field it will run validations for that field when the reactive method is called.
So without even submitting the form and only clearing a text input field it should return a required validation error?
But if you call it explicitly in a function somewhere it’ll validate all the form data.
Theoretically.
How does Filament get the state of other fields without this happening then? Using raw state?
If you clear the field and call getState() it should throw a validation error.
Can’t say for sure but that would be my guess.
Hmm okay that would make more sense then I guess. Its all good just curious. I was just having issues with the logo really. Is using
getState()
okay as an exception for the logo?The Get class doesn’t even touch getState or getRawState. It’s getting the value directly from the livewire instance.
Is there a way to do this for my use case so I can follow Filament's conventions?
Only real caveat to it would be that it’ll store files on your server that you may not want. Ie someone uploads a logo, then turns around and upload a second one.
GitHub
filament/packages/forms/src/Get.php at 3.x · filamentphp/filament
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
That’s what the Get class is doing. Maybe something there, but you’re still going to have to manually save the file somehow for it to be viewable in a preview.
Okay thank you.
So I cant grab the temporary url? How else would Filepond be previewing it?