Jump to content
J_Szwarga

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

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?

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Hmm... I'm not sure.

Maybe you can check out the code from: 

You could also check the code from:

Ryan also shows an example

Hope that helps point you in the right direction.  Others here may chime in as well.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...