SpinOnSubmitJS is a lightweight JavaScript library that simplifies the process of indicating loading state and disabling a submit button during asynchronous actions, such as form submissions. It provides an easy way to add a spinner to the submit button, improving user experience and preventing multiple form submissions. This library is perfect for web developers looking to improve the interactivity of their web pages without writing complex JavaScript code.
SpinOnSubmitJS can be installed via NPM. To add it to your project, simply open your terminal and run the following command:
npm install spinonsubmitjs
Incorporating SpinOnSubmitJS into your project is easy. Just follow the subsequent steps:
Here's an example of how you might use `createSpinnerButton`:
createSpinnerButton(
'submitBtn',
'myForm',
function(data) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
var firstName = data.firstName;
var lastName = data.lastName;
if (firstName === '' || lastName === '') {
reject('All fields must be filled!');
} else {
alert("Submitted!\nFirst Name: " + firstName + "\nLast Name: " + lastName);
resolve();
}
}, 2000);
});
},
function(error) {
alert(error);
console.error(error);
},
'white', // Spinner color
'right', // Spinner position
false // hideLabelWhileLoading
);
Below is a live example of a form using SpinOnSubmitJS. When you click the submit button, the form data is gathered and an alert is displayed with your first and last name. During this time, the submit button is disabled and a spinner is displayed.
The source code for SpinOnSubmitJS is available on GitHub. You can view it, download it, fork it, or contribute to it by visiting the following link: SpinOnSubmitJS GitHub Repository.
SpinOnSubmitJS is also available as an NPM package. You can add it to your project by running `npm install spinonsubmitjs` or visit the NPM package page at SpinOnSubmitJS NPM Package for more information.