form-ajax

Submitting a form with AJAX

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
form-ajax
1.0.22 years ago4 years agoMinified + gzip package size for form-ajax in KB

Readme

FormAjax
npm version

Installation

``npm install form-ajax --save``

Usage

import FormAjax from 'form-ajax';

const formContainer = document.querySelector('form');
const formAjax = new FormAjax(formContainer, {
    disabledClass: 'disabled', // applied to the form during request
});

form.on('beforeSubmit', form => { // formContainer
    // validate form
    
    if (formIsNotvalid) {
        return false;
    }
    
    return true;
});

form.on('success', data => { // XMLHttpRequest
    console.log(data.response);
    console.log(data.status);
});

form.on('error', data => { // XMLHttpRequest
    console.log(data.response);
    console.log(data.status);
});