Monday, September 19, 2011

Mootools FormCheck: Ajax configuration

Currently I need to use a, ready to use, form to login....
I decide to use form-check of mootools available at:
http://mootools.floor.ch/docs/formcheck/files/formcheck-js.html

This is my configuration to allow ajax authentication(script tag in the head...)
No other configuration. The rest is the pure standard form-check:

<script type="text/javascript">
        window.addEvent('domready', function(){loginFormCheck = new FormCheck('formular', {
            submit : false,
            submitByAjax: true,
            submitAction: './loginManager',                //Action page used to submit the form data to.
            submitMethod: 'post',                //Method used to submit the form, valid options : 'post' or 'get'
            onAjaxRequest : onAjaxRequest,                //Function to fire when the Request event starts
            //onAjaxComplete : onAjaxComplete,            //Function to fire when the Request is complete, before and regardless of Success or Failure
            onAjaxSuccess : onAjaxSuccess,   
            display : {
                errorsLocation : 1,
                indicateErrors : 2,
                flashTips : true,
                fadeDuration : 1500,
                scrollToFirst : false
            },
            alerts : {
                required : 'This field is ablolutely required! Please enter a value'
            }
        })});
       
        function onAjaxRequest () {
            document.getElementById("loadingDiv").style.display = "block";
        }
       
        function onAjaxSuccess () {
            document.getElementById("loadingDiv").style.display = "none";
            window.location = "./home.jsp";
        }
       
       
    </script>

loadingDiv is a div where I have a simply "loading" animated gif.
loginManager is my servlet the manage the login logic.
Bye

No comments:

Post a Comment