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

rescan() method changes field orig value if it was empty #123

Open SYTDeath opened 7 years ago

SYTDeath commented 7 years ago
    var rescan = function() {
      var $form = $(this);
      var fields = $form.find(settings.fieldSelector);
      $(fields).each(function() {
        var $field = $(this);
        if (!$field.data('ays-orig')) {
          storeOrigValue($field);
          $field.bind(settings.fieldEvents, checkForm);
        }
      });
      // Check for changes while we're here
      $form.trigger('checkform.areYouSure');
    };

Above is the rescanmethod. On line 6, the expression returns true if

In reality, fields may be empty when page is loaded for the first time. Running this method will lose the original ays-orig values of those fields.

Is there any reason why empty fields have to update their ays-orig values?

sb-relaxt-at commented 7 years ago

Just found this bug too. From my point of view checking for undefined seems to work.