AJAX Forms
A class that simplifies AJAX form submission.
Installation
Install the package with NPM:
npm install @donutteam/ajax-forms
Usage
Simply import the class:
import { AJAXForm } from "@donutteam/ajax-form";
And then call bindAll
:
AJAXForm.bindAll();
That will bind all forms on the page with the ajax
class on them by default. This can also be customized, see Configuration below.
If you prefer, you can also manually construct an AJAXForm
by passing in a form element:
const myForm = document.querySelector("form.my-form");
new AJAXForm(myForm);
Configuration
The AJAXForm
class contains various static members that can be changed to configure its functionality.
Below are the default options and a brief explanation of what they do:
AJAXForm.selector = "form.ajax";
AJAXForm.defaultCredentialsMode = "same-origin";
AJAXForm.messageListSelector = "ul";
AJAXForm.successCodeRegExp = /SUCCESS_(.*)/;
AJAXForm.successCSSClass = "success";
AJAXForm.errorCSSClass = "error";
License
MIT