jQuery Forms v1.0.9

jQuery Plugn Macros

Configuration

Name Type Description
postUrl String Url which will post form data to. If null, will use 'action' attribute of form
callback Function Called after successful processing with the response object and the form
errorHandler Function Default displays messages and also calls errorCallback if provided. Arguments are 'resp', 'form', 'valiationMessageSelector', 'errorCallback'
error Function A simpler error callback, is called after form UI is updated
validate Function Custom validation method. Arguments are 'form'. 'form' is jQuery object form. Can return true if the form is valid.
onValid Function Callback will be called when all fields are valid. Arguments are 'form'. 'form' is jQuery object form.
doPostForm Boolean Allow post form data via AJAX automatically or not
confirmMessage String The confirmation message after posting data fom to server successfully
valiationMessageSelector String Selector of validation message
validationFailedMessage String Message will be showed when validation is failed
networkErrorMessage String The error network message
emailErrorMessage String The error message when email fields are invalid
requiredErrorMessage String The error message when required fields are invalid

 

Default Configuration

{
    postUrl: null, // means to use the form action as url
    callback: function() {

    },
    errorHandler: function(resp, form, valiationMessageSelector, errorCallback) {
        try {
            var messagesContainer = $(valiationMessageSelector, form);
            flog('status indicates failure', resp);
            if (resp) {
                if (resp.messages && resp.messages.length > 0) {
                    for (i = 0; i < resp.messages.length; i++) {
                        var msg = resp.messages[i];
                        showMessage(msg, form);
                    }
                } else {
                    showMessage('Sorry, we couldnt process your request', form);
                }
                showFieldMessages(resp.fieldMessages, form)
            } else {
                showMessage('Sorry, we couldnt process your request', form);
            }

            messagesContainer.animate({
                height: 'show',
                'padding-top': 'show',
                'padding-bottom': 'show'
            }, 100);
        } catch (e) {
            flog('ex', e);
        }
        if (errorCallback) {
            errorCallback();
        }
    },
    error: function() {

    },
    validate: function(form) {
        return true;
    },
    onValid: function(form) {

    },
    doPostForm: true,
    confirmMessage: null,
    valiationMessageSelector: '.pageMessage',
    validationFailedMessage: 'Some inputs are not valid.',
    networkErrorMessage: 'Sorry, there appears to be a problem with the network or server. Please check your internet connection. If you're connected ok this might be a glitch in the system.',
    emailErrorMessage: 'Please check the format of your email address, it should read like ben@somewhere.com',
    requiredErrorMessage: 'Please enter all required fields'
}