Jump to content

InputfieldFile extensions..."open dialog" not affected by field's extensions setting


J_Szwarga
 Share

Recommended Posts

Here's my code for using the InputfieldFile in a form on a backend page (Process module)

$f = $this->modules->get('InputfieldFile');
    $f->name = "mp3_file";
    $f->label = "Mp3 Audio File";
    $f->extensions = "mp3";
    $f->maxFiles = 1;
    $f->setMaxFilesize("200M");


    $form->append($f);

For "extensions" I've tried both ".mp3" and "mp3" without the period.

The mp3 extension does show up in the form field UI....

image.png.d5c38144879f661e602bc2a272f7291e.png

 

But it does NOT limit which files are visible in the "open" dialog box to choose a file to upload...

image.png.f51d65588789aec0c8e8a2b9c0528576.png

Furthermore, it does not limit which files can be opened and uploaded. Went through the source code and I'm still puzzled why this isn't working as expected.

I would expect that the module would use the extensions to add an "accept" property to the input HTML element (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept)

But inspecting the html, there is no "accept" property on the resulting input element....and in the source code of InputfieldFile.module, a search for "accept" turns up 0 results....

Anyone have a clue for me?

Link to comment
Share on other sites

  • J_Szwarga changed the title to InputfieldFile extensions..."open dialog" not affected by field's extensions setting

The "open" dialog box you see is a Windows only thing.  Mac users don't have the same dialog.  So it may be working as intended.

What happens if you try to upload a pdf file? Does it give you an error?  What happens when you upload an mp3 file?  Does it give you an error?

Link to comment
Share on other sites

No errors, I can upload any file type.

The accept parameter is a html web thing, not just a Windows thing, from all indications here:. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept

For now I just added the accept attribute manually to the field. I'm surprised this is not done by default? What other functionally does extensions property provide if it doesn't limit what file types can be uploaded?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...