codedance / jquery.AreYouSure

A light-weight jQuery "dirty forms" Plugin - it monitors html forms and alerts users to unsaved changes if they attempt to close the browser or navigate away from the page. (Are you sure?)
508 stars 145 forks source link

version 1.8 seems not to work on <select><option> with empty value #55

Closed BartTriple closed 9 years ago

BartTriple commented 9 years ago

when using version 1.7 from the demo all works as expected, in version 1.8 changes on select are not captured? mycode:

joelbarker2011 commented 9 years ago

I can verify that this problem exists in 1.8.0. Create a form with a select box; make the select box's default value blank. When the select box is changed to a different (non-blank) value, the "dirty" event is not fired. (Testing in Firefox 31, the select box's "onchange" event DOES still fire. Changing other input fields on the form still fires the "dirty" event.)

This problem does not occur when the select box has a non-blank value to start with.

tus124 commented 9 years ago

I agree. It seems like code is mistakenly takes blank value with undefined. Earlier version 1.5 does not have this issue.

DevanB commented 9 years ago

Someone should consider merging this in. We are having this problem. I just decided to do the hard code change in our local file since I can't wait for this to be merged in.

Did notice that with the change, if you change the value from a blank value, it fires the dirty event, but if you change it back to the value that it was upon loading the page, it doesn't fire a clean event.

codedance commented 9 years ago

Hi Guys, Sorry about being offline for a few days. I agree. There is already a related change in the 1.9-dev branch. I'll look at releasing 1.9 and ensuring the use-case outlined here is also address.

Just a git of history: In older versions of Are-You-Sure, we handled selects by converting to a string manually by looping through selected elements and concatenating a string. This code was a bit hacky but worked. It was cleaned up to use the .val() array return - this removed about 15 lines. The downside has been a few side-effect related bugs.

codedance commented 9 years ago

I did a bit of testing and playing around with a few alternate solutions. I've decided to revert select handling back to the 1.7 logic. It's a little more complicated, but it works on all versions of jquery back to 1.4 and stood the test of time for the past few years.

I agree this is an annoying bug so I'll push version 1.9 today.

joelbarker2011 commented 9 years ago

This has corrected the problem for me. Thanks!