I have a settings page with some custom fields, one of them is a file_upload
field which is defined like this:
[
'name' => 'Video file',
'id' => 'video_file',
'type' => 'file_upload',
'required' => true,
'max_file_uploads' => 1,
'max_status' => false,
'attributes' => [
'accept' => 'video/*',
'onchange' => 'video_preview_update_src(this.files[0])',
],
],
Whenever I submit the settings page, I get an error that This field is required.
even when the file is already selected and uploaded. And the accept
attribute is not working which should filter the selected files to accept video files only.
But this snippet of code works perfectly when I set the type of the custom field to file
, not file_upload
.
I noticed that once the file is selected and uploaded, the value
attribute of the <input>
tag is not updated, and that's why it considers the field empty.
And to make the accept
attribute work with the file_upload
field, it should be added to the Select Files button <input>
tag (the second marked one in the screenshot).