Chris Simpson
Chris Simpson

Reputation: 8000

Validation and Firefox's input caching

When you refresh/reload a page or use the back button, Firefox is kind enough to repopulate your inputs with what was entered before you navigated away.

Though this is a nice feature it does not trigger my jquery validation and the unsaved changes warning I add to my pages.

Is there a way to either disable this feature in Firefox (without renaming every control every time) or capture the firefox events?

Upvotes: 0

Views: 799

Answers (3)

Nick Craver
Nick Craver

Reputation: 630599

After your .validate() call in document.ready, also call .valid() once to trigger validation as well, like this:

$(function() {
  $('#myForm').validate({ /* options here */ });
  $('#myForm').valid();
});

Upvotes: 1

Nicholas Wilson
Nicholas Wilson

Reputation: 9686

Could I suggest you add a delayed function to validate and check for form content a few seconds after page load? That would probably be the safest way to catch all browsers, some of which only insert saved form data once the whole page has finished loading.

Upvotes: 0

Boris Guéry
Boris Guéry

Reputation: 47614

You can use the trigger() method to trigger any events (custom or not).

Suposing you have a validate event :

$(document).ready(function()
    {
        $('#yourform').trigger('validate');
    }
);

If your validation plugin makes use of a function to validate, then simply do :

$(document).ready(function()
    {
          validate($('#yourform'));
    }
);

which will be triggered when your document is ready.

Eventualy use setTimeout to avoid loading time during the way to browser load the cached input values.

Upvotes: 0

Related Questions