Code Monkey home page Code Monkey logo

jquery-daf's Introduction

jquery daf (django ajax forms)

jQuery plugin making django forms submit through ajax, easily overridable settings

Using csrf token from cookie

Installation

  • Download jquery-daf.js to /static/js directory
  • Include it in your html
  • Bind and Initialize the plugin, check demo

Dependencies

Default options

On instantiation these are overridable, instance and form is passed to functions

var defaults = {
    container: $('body'),
    
    resetSubmitEvents: true,
    // to reset the propagation of submit event to other plugins
    
    formSets: '', 
    // specify form element placeoholder of the formset, we cannot have more form tags inside a form so replace it
    
    formSetItem: 'tbody tr', 
    // formset table row selector, only used when formSets is specified
    
    captchaField: '#div_id_captcha', 
    // the holder for the google captcha ... used for error message
    
    fieldHolder: '.form-group',
    // specify the field block holder where we can manipulate the field error messages, inside of selector

    processErrors: null,
    // define as a function(form, response){} to use this instead default function

    afterResponse: null,
    // define as a function(form, response){} to use this instead default function
    
    removeErrors: function(form, instance){ 
    // error remover before submit
        $(form).find('.has-error').each(function (item) {
           $('div.help-block', item).remove();
        }).removeClass('has-error');
    },
    
    beforeSubmission: function(form, instance){ 
    // after errors are cleared, preprocessing can be done here
        $(instance.options.submitBtn).button('loading');
    },
    
    canSubmit: function(form, instance){
    // hook to interrupt the submisssion process, return false to stop it
        return true;
    },
    
    onSuccess: function(form, response){
    // response from server is 200
        toastr.success(response['message']);
        if (response['redirect_url']) {
            setTimeout(function() {window.location.href = response['redirect_url']}, 1500)
        }
    },
    
    postSuccess: function(form, response, instance) { 
    // this happens after success post processing can be done here
        $(instance.options.submitBtn).button('reset').hide('slow');
        $(form).hide('slow')
    }
    
    errorHolders: {}
    // used for defining custom error holder for specific fields like: gender: '.gender-error'
};

jquery-daf's People

Contributors

akifkuwaitnet avatar zhgabor avatar

Watchers

 avatar  avatar  avatar

Forkers

akifkuwaitnet

jquery-daf's Issues

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.