xhr-form-submitter

1.1.9 • Public • Published

xhr-form-submitter

Support me on Patreon Buy me a book PayPal Ask me anything Version Downloads Get help on Codementor

Buy Me A Coffee

A lightweight JavaScript library to submig forms via XHR requests.

☁️ Installation

# Using npm
npm install --save xhr-form-submitter

# Using yarn
yarn add xhr-form-submitter

📋 Example

window.onload = function () {
    var formEl = document.getElementById("myForm")
      , checkboxEl = document.getElementsByName("xhr")[0]
      , nameEl = document.getElementsByTagName("name")[0]
      , mbErrorEl = document.getElementById("mb-error")
      , mbSuccessEl = document.getElementById("mb-success")
      , formToSubmit = new XHRFormSubmitter({
            form: formEl
          , disableOnSubmit: true
        })
      ;

    formEl.addEventListener("submit", function (e) {
        if (!checkboxEl.checked) { return; }
        try {
            mbErrorEl.style.display = "none";
            mbSuccessEl.style.display = "none";
            formToSubmit.submit(function (err, data) {

                var mb = null;
                if (err) { mb = mbErrorEl; }
                else { mb = mbSuccessEl; }

                mb.innerHTML = err || data;
                mb.style.display = "block";
                mb.classList.remove("fadeInUp");
                mb.classList.add("fadeInUp");
            });
        } catch (e) {
            console.error(e.message);
        }
        e.preventDefault();
    });
};

❓ Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. 🐛
  3. For direct and quick help, you can use Codementor. 🚀

📝 Documentation

XHRFormSubmitter JavaScript Library

A lightweigt JavaScript library that do one thing: submiting via XHR requests. This doesn't depend on jQuery!

For more information, see README file. Report bugs in the GitHub repository.

Developed with love by Ionică Bizău.

getFormData()

Creates an object containing the names and the values of the form inputs.

Return

  • Object The form data object (name: value)

disableInputs()

This function disables the inputs. It's cool to be called before submiting the form.

Return

  • Object The XHRFormSubmitter instance

enableInputs()

This function enables the inputs. It's cool to be called after receiving the response from server.

Return

  • Object The XHRFormSubmitter instance

submit(submitOps)

Submit the form using a XMLHttpRequest.

Params

  • Object submitOps: The submit options

Return

  • Object The XHRFormSubmitter instance

😋 How to contribute

Have an idea? Found a bug? See how to contribute.

💖 Support my projects

I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).

However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:

  • Starring and sharing the projects you like 🚀

  • Buy me a book—I love books! I will remember you after years if you buy me one. 😁 📖

  • PayPal—You can make one-time donations via PayPal. I'll probably buy a coffee tea. 🍵

  • Support me on Patreon—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).

  • Bitcoin—You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6

Thanks! ❤️

📜 License

MIT © Ionică Bizău

Package Sidebar

Install

npm i xhr-form-submitter

Weekly Downloads

2

Version

1.1.9

License

MIT

Unpacked Size

17.4 kB

Total Files

5

Last publish

Collaborators

  • ionicabizau