Forum Moderators: open

Message Too Old, No Replies

Input accept attribute in Firefox

         

Rain_Lover

8:06 am on May 11, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



According to MDN accept=[MIME type] is supported in Firefox:
source: [developer.mozilla.org ]

However, I tried the following to no avail:

<input type="file" accept="text/html">



Is it a bug or am I missing something?

phranque

9:36 am on May 11, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



is the FF version >= 16 ?

Rain_Lover

9:58 am on May 11, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



The newest version.

drhowarddrfine

3:19 pm on May 11, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Works for me.

Fotiman

12:53 am on May 12, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I tried the following to no avail

What does that mean? What was the actual behavior, and what did you expect?

Rain_Lover

2:14 am on May 12, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



@Fotiman:

Sorry for the incomplete question!
It doesn't filter the HTML files: demo [jsfiddle.net].

Fotiman

2:11 pm on May 12, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here is what I don't understand: How could this possibly ever work? When opening a file from the file system, there is no explicit MIME type defined. That is, when a file is served from a web server over HTTP, there are certain HTTP headers that identify the MIME type. The same is not true on the local file system. At best, file extensions could be mapped to a MIME type (for example, all .html files might map to text/html), but that does not guarantee that the file does, in fact, contain text/html content.


If the value of the type attribute is file, this attribute indicates the types of files that the server accepts;

(Emphasis is mine)
This is meant to indicate the type that the server accepts. So suppose you specify this as text/html, but then Firefox lets you choose a .exe file (for example). If you submit that form, does the .exe file actually get transmitted to the server as part of the form submit? In other words, could Firefox be handling this at submit time instead of filtering it at file selection time?

Rain_Lover

6:37 am on May 13, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



This is meant to indicate the type that the server accepts.


According to the spec [w3.org], the accept attribute may be specified to provide user agents with a hint of what file types will be accepted. The accept attribute filters the files you see in the Open dialog so you can easily find and work with the desired files among the clutter while you can still select All Files and see/select other files. Then this attribute isn't meant to be a validation tool -- just for user convenience and to know which file types will pass the validation on the server.

Fotiman

1:42 pm on May 13, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ah, looking at the actual spec... I was just being lazy. :)

User agents may use the value of this attribute to display a more appropriate user interface than a generic file picker

(Emphasis is mine)
It looks like this is still one of those ambiguous attributes that doesn't have a strict definition of what user agents should do, and instead leaves it open.

But yeah, Firefox certainly doesn't seem to be doing anything with this attribute.

rainborick

3:16 pm on May 13, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I got curious and did some simple tests with Firefox 29, IE 11, and Chrome 34. Firefox did seem to be buggy. Specific MIME-types all failed despite the claim on the page referenced above that it was supported. Firefox only filtered the file selection list when I used "audio/*", "image/*" or "video/*". No variation of "text/" had any filtering. The others looked to behave per the spec, even with multiple, specific MIME-types.

It looks like support for this attribute is spreading, but slowly. IE support started with version 10. Opera and Safari have no support yet. And Mozilla's chart didn't show any support on mobile devices. So, at best, you can use 'accept' to augment a form, but you certainly can't rely on it.

Rain_Lover

3:31 pm on May 13, 2014 (gmt 0)

10+ Year Member Top Contributors Of The Month



Opera and Safari have no support yet.


Not sure about Safari as I'm on Windows, but it works in the latest version of Opera for me.

rainborick

7:07 pm on May 13, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I was just going by the chart over on the Mozilla page.

While investigating this a bit, I was very disappointed to see in the Mozilla bug reports that it looked like nobody in the project was working on the remaining new HTML 5 input types like 'datetime', 'color', or even 'search'. It seems like such simple stuff to do - from the outside looking in, of course.