Class Index | File Index

Classes


Class LABKEY.Form

LABKEY.Form A utility class for tracking HTML form dirty state and warning the user about unsaved changes.
Defined in: Form.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
LABKEY.Form(config)
Constructs a LABKEY.Form object.
Config Summary
Config Attributes Config Name and Description
 
A reference to the HTML form element you want to track.
 
Set to false to stop this from displaying the warning message when the user attempts to leave the page while the form is still dirty.
 
A warning message to display if the user attempts to leave the page while the form is still dirty.
Method Summary
Method Attributes Method Name and Description
 
Returns true if the form is currently dirty, false otherwise.
 
Sets the form's dirty state to clean
 
Sets the form's dirty state to dirty
Class Detail
LABKEY.Form(config)
Constructs a LABKEY.Form object. This object may be used to track the dirty state of an HTML form and warn the user about unsaved changes if the user leaves the page before saving.
     <form id='myform' action="..." method="POST">
     <input type="text" name="Example" size="10"/>
     <input type="submit" value="Save"/>
     <button onclick="window.location.back();">Cancel</button>
     </form>

     <script type="text/javascript">
     var _form;
     LABKEY.Utils.onReady(function(){
        //create a new LABKEY.Form to track the dirty state of the form above.
        //if the user tries to navigate away while the form is dirty, it will warn the user
        //and provide an option to stay on the page.
        _form = new LABKEY.Form({
            formElement: 'myform',
            warningMessage: 'This is a custom warning message' //omit to get standard warning message
        });
    });
     </script>
Parameters:
{Object} config
A configuration ojbect containing the following properties:
Config Detail
{Element} config.formElement
A reference to the HTML form element you want to track.

{Boolean} config.showWarningMessage
Set to false to stop this from displaying the warning message when the user attempts to leave the page while the form is still dirty. If you only want to use this class to track the dirty state only and not to warn on unload, set this to false.

{String} config.warningMessage
A warning message to display if the user attempts to leave the page while the form is still dirty. If not supplied, a default message is used.
Method Detail
isDirty()
Returns true if the form is currently dirty, false otherwise.

setClean()
Sets the form's dirty state to clean

setDirty()
Sets the form's dirty state to dirty

Documentation generated by JsDoc Toolkit 2.3.2 on Thu Mar 16 2017 20:36:35 GMT-0000 (UTC)