Upload field type on edit required issue
See original GitHub issueHey, i’m fairly new to backpack
i have a field in my MusicCrudController
:
$this->crud->addField([ // Music Upload 'name' => 'music', 'label' => 'Music', 'type' => 'upload', 'upload' => true, 'disk' => 'public', ]);
everything is ok when i add a new Music using CrudController, but when i try to edit i get the following message:
Please fix the following errors: The music field is required.
even though the field show the address of the uploaded music Musics/9c30dc40684eaefb144fda9aca2ae414.mp3
I’m so frustrated. Can anyone help me with this?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:26 (7 by maintainers)
Top Results From Across the Web
Making 'file' input element mandatory (required) - Stack Overflow
You can try applying the form attribute to the input field to make sure it is related to your form. <input type="file" name=""...
Read more >File Upload Error and missing required fields - Jotform
To edit the allowed file types, select the upload field and then click on the Properties gear. Then select the Options tab and...
Read more ><input type="file"> - HTML: HyperText Markup Language | MDN
This string is a comma-separated list of unique file type specifiers. Because a given file type may be identified in more than one...
Read more >Custom edit form with a required field auto check in - TechNet
1) Have at least one required field in a document library. 2) Create a custom edit form for the doc lib. 2) upload...
Read more >A Complete Guide to the WPForms File Upload Field
To view these options, you'll need to open the form builder and click on the File Upload field in the preview area to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I know this is a closed issue, but I found this after searching for a solution for a similar issue. I believe I have worked out the cause of the problem. If you have an upload field named
file_upload
, the javascript component in backpack will submit this as a singlefile
type input field on create. However, when you edit the file, this field is not present unless you try to upload a new file. As a result, the Laravel validation doesn’t see afile_upload
key in the request input, and throws the validation error.The problem then comes if someone clicks the remove button when editing, as the javascript of the form element will create an empty
file_upload
field, which will trigger the removal of the file through the standard crud process, as this is viewed as an effort to delete the uploaded object.So the question is then, how to have validation that checks that either the input doesn’t have a
file_upload
attribute (in which case we know that the Crud won’t delete the current file), or if it does that it is not empty.Awesomely, it turns out Laravel has you covered. The validation rule just needs to be:
@splatEric - thanks a lot for clearing that up for me.
sometimes
sounds PERFECT then 😃 I’ll use it myself the next time I need this, thanks a lot for teaching me about it.