MozillaZine

Why does Firefox v42 fire onchange every time?

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
CharlesEF
 
Posts: 132
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Post Posted December 14th, 2015, 10:04 am

Hi All,

Please consider the following code:
Code: Select all
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Title</title>
<script type="text/javascript">
 function check()
 {
  alert('Hi!');
 }
</script>
</head>
<body>
<input type="file" id="filePicker" onchange="check();">
</body>
</html>

Firefox will show the alert box every time a file is chosen, even when the file is the same. I have also tested in IE11 and Chromodo and both work as they should.

patrickjdempsey

User avatar
 
Posts: 23734
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC

Post Posted December 14th, 2015, 10:51 pm

This person thinks Chrome gets it wrong and it should fire even if it's the same file:
http://stackoverflow.com/questions/6623 ... -in-chrome

And I agree with them. If your user has manually invoked the file selector and chosen the "same" file, then the browser should trust the user's judgement. Example:

- User selects "1.txt". First onchange event fires... confirmation popup or whatever.
- User is looking at their text editor and realizes they made an important spelling error, so they fix it and save over the original.
- Users selects "1.txt" again.

If nothing happened at all after the second selection... I think most users would be very confused. Which version of the file will be uploaded? The one with the spelling mistake or the fixed one?? That sounds very confusing to me.
Tip of the day: If it has "toolbar" in the name, it's crap.
What my avatar is about: https://addons.mozilla.org/en-US/seamonkey/addon/sea-fox/

CharlesEF
 
Posts: 132
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Post Posted December 15th, 2015, 2:27 am

I'm not talking about different versions of the same file. I'm talking about the same file, period. The event is called 'onchange' not 'onchosen'. Are you saying that this is the new behavior of Firefox? Or, are you saying Firefox has been doing this for awhile? I have just started getting complaints from users about this.

patrickjdempsey

User avatar
 
Posts: 23734
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC

Post Posted December 15th, 2015, 3:25 am

That stackoverflow page is from 2011, so it's not new. Although I don't think I've ever used a website that even did that to begin with.

Also... how do you or the browser know it's the *same file period*? I think Chrome and IE are making an assumption that can't really be made. If the user has manually invoked the file selector, then that in itself represents a change in state from my viewpoint... regardless of the file chosen. And it seems like it would be unexpected for the website to *not* respond when the user does that.
Tip of the day: If it has "toolbar" in the name, it's crap.
What my avatar is about: https://addons.mozilla.org/en-US/seamonkey/addon/sea-fox/

trolly
Moderator

User avatar
 
Posts: 39878
Joined: August 22nd, 2005, 7:25 am

Post Posted December 15th, 2015, 5:31 am

Define "same file":
- same name
- same path
- same size
- same last modified date
- same checksum
...
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.

CharlesEF
 
Posts: 132
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Post Posted December 15th, 2015, 5:52 pm

patrickjdempsey wrote:That stackoverflow page is from 2011, so it's not new. Although I don't think I've ever used a website that even did that to begin with.

Also... how do you or the browser know it's the *same file period*? I think Chrome and IE are making an assumption that can't really be made. If the user has manually invoked the file selector, then that in itself represents a change in state from my viewpoint... regardless of the file chosen. And it seems like it would be unexpected for the website to *not* respond when the user does that.

I know it's the same file because I'm the one choosing it. I started testing once I got complaints. I don't think it's the browsers job to protect the user. At this time I've only tested the file input but what about other fields? Like drop downs and text inputs? Has the 'onchange' event been changed for them also?

CharlesEF
 
Posts: 132
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Post Posted December 15th, 2015, 5:58 pm

trolly wrote:Define "same file":
- same name
- same path
- same size
- same last modified date
- same checksum
...

Yes, to everything. As far as I care it doesn't matter about any of those things, just the file name. When I open a file input by mistake I just click the cancel button and I don't have to worry about the event firing again. But, a lot of users don't do that, sadly.

Anyway, I didn't come here to argue about it. I just want to know if this is the intended behavior or a bug?

patrickjdempsey

User avatar
 
Posts: 23734
Joined: October 23rd, 2008, 11:43 am
Location: Asheville NC

Post Posted December 15th, 2015, 8:09 pm

CharlesEF wrote:I don't think it's the browsers job to protect the user.

And I don't think it's the browser's job to ignore the user when they've gone out of their way to do something.

Anyway, I think we've answered your question. It appears to be just a difference in how the browsers do things. This is why it's always important to test your work in ALL browsers.
Tip of the day: If it has "toolbar" in the name, it's crap.
What my avatar is about: https://addons.mozilla.org/en-US/seamonkey/addon/sea-fox/

CharlesEF
 
Posts: 132
Joined: November 21st, 2003, 4:56 am
Location: Edinburg, Texas

Post Posted December 16th, 2015, 8:09 am

Ok, thanks for everyone's input. While I don't agree with the reasoning we'll never change each others minds.

Lemon Juice
 
Posts: 771
Joined: June 1st, 2006, 9:41 am

Post Posted December 28th, 2015, 3:58 pm

I tend to agree with patrickjdempsey on this. But currently no browser handles this perfectly - Firefox may fire the event even if the same and unchanged file has been selected while Chrome may not fire the event if the file has changed. A clever browser might check if the selected file really has the same content as the previous one (for example, by computing its hash) and fire the event only if the new file is really different.
*** SeaMonkey — weird name, sane interface, modern bowels ***
Mouse Gestures for SeaMonkey/Firefox
Convert Fx and TB extensions to SeaMonkey

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 1 guest