Giter VIP home page Giter VIP logo

jquery-dontjustleaveme's Introduction

jquery-dontJustLeaveMe

Checks if the form is the same before leaving the page as it was when we came in, if not, make sure they want to leave. Has special support for django admin forms, but should work with any form.

Usage

$('form').dontJustLeaveMe();

Options

All the options are optional.

serializeForm

The function to use to serialize a form. Takes a form and returns a string.

errorMessage

The message to use when there is unsaved data. The default is "You have unsaved changes, are you sure you want to leave?"

jquery-dontjustleaveme's People

Contributors

gavinwahl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

web010

jquery-dontjustleaveme's Issues

multiple forms give conflict

[reported by @web010]

If a page contains multiple forms, a changed form cannot be submitted. All forms are checked and when the last form in the checker was not the submitted one, the checker gives a 'false' on 'was_submitted' and a true on 'changed input', which results in the returnmessage.

ckeditor is not being checked.

If a page contains multiple forms, a changed form cannot be submitted. All forms are checked and when the last form in the checker was not the submitted one, the checker gives a 'false' on 'was_submitted' and a true on 'changed input', which results in the returnmessage.

Second problem is the checking of an editor which might be part of the form. I solved this by adding the options with "editor:check_editor". check_editor (default=false) is a callback function in a custom script. In the function dontJustLeaveMe I made the following change:
$(window).on('beforeunload', function() {
if ( ! was_submitted && options.editor){
dirty_editor = options.editor();
}
if ( ! was_submitted && (dirty_editor || options.serializeForm($form) != initialState) ){
return options.errorMessage;
}
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.