Only allow clipboard pasting, not typing, into a field.
I have a field where users should be pasting in content from another tool, and not directly entering information into a Textarea. Is there a way to control a field so the user cannot type into the Textarea, but can paste into it. Or is there a better method than using a Textarea to let the user throw stuff from the clipboard into the form?
OR
Is it possible to use a fileUpload, but instead of uploading the file to my storage, it just pulls the content of the (xml) file and fills in a readOnly field?
Solution:Jump to solution
You would use the closure Get and Sets
```php
->afterStateUpdated(function($state, $get, $set) {
$state = your file // do processing...
6 Replies
thinking about it more I much strongly prefer the file upload method if it's possible.
You can allow file upload, then afterStateUpated process the file and populate it's content into the form. However, when you have disabled fields you cannot save them natively as we remove them. You'll need to do some custom work to make this work
I've used ->readOnly with fields to make them not editable but still insert into the DB fine.
What do I pass into the function on afterStateUpdated on the file to get the contents? Does $state contain the file?
Solution
You would use the closure Get and Sets
Last question for now. If I don't want the file itself stored or put into the database, is there anything special I need to do? Or if I just have the FileUpload::make('nonexistent_field') will that work?
I'm having a lot of trouble getting the content of the File i'm uploading.
I've tried
both with similar results
the ddd of $state shows me the actual path for the file as realPath
Try $state->getPath()
Or $state->getRealPath() if you need the full path.