npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

single-submit

v2.0.1

Published

The Single Submit JS library offers a simple solution for improving button functionality in server-side applications.

Downloads

13

Readme

Single Submit Js

In scenarios involving actions like file uploads or form submissions, waiting for server responses can be time-consuming. By integrating this library, enhance user experiences with a processing indicator and prevent duplicate submissions until a response is received, resulting in a more efficient interaction.

Key Features

  • Prevent duplicate form submission. 🚫
  • Native HTML form validation. ✅
  • Works independently of any CSS framework. 🌐
  • Compact file size of less than 1KB. 📦
  • Quick setup with a CDN link. 🚀
  • Supports customizing processing indicators. 🛠️

Single Submit Example

Quick Start

<!DOCTYPE html>
<html lang="en">
  <body>
    <form
      method="post"
      data-ss-type="single-submit-form"
      data-loading-text="Submitting...">
      <!-- Your form fields here -->

      <button type="submit">Submit</button>
    </form>

    <!-- Add CDN link -->
    <script
      src="https://cdn.jsdelivr.net/npm/[email protected]/dist/single-submit.min.js"
      integrity="sha256-Ig68U756uj/lhygwo6cvQoKZgrpunyLN1+Zpl+pWyRk="
      crossorigin="anonymous"></script>

    <!-- Initialize on load -->
    <script type="text/javascript">
      window.addEventListener("load", () => {
        SingleSubmit.init();
      });
    </script>
  </body>
</html>

Installation

Using CDN link:

<script
  src="https://cdn.jsdelivr.net/npm/[email protected]/dist/single-submit.min.js"
  integrity="sha256-Ig68U756uj/lhygwo6cvQoKZgrpunyLN1+Zpl+pWyRk="
  crossorigin="anonymous"></script>

Using npm package:

npm i single-submit

Once the package is installed, you can import the library using import or require approach:

// Using default default export.
import SingleSubmit, { SingleSubmitOptions } from "single-submit";

// or If you use require for importing, only default export is available.
const SingleSubmit = require("single-submit").default;
const { SingleSubmitOptions } = require("single-submit");

Configuring forms

Add the data-ss-type="single-submit-form" attribute to your form and optionally include the data-ss-loading-text attribute to specify the text displayed during processing. Here's an example:

<form
  method="post"
  data-ss-type="single-submit-form"
  data-ss-loading-text="Submitting...">
  <!-- Your form fields here -->
  <button type="submit">Submit</button>
</form>

Customize the process indicator

Out of the box, there is one indicator available: spinner-border-single-submit. You can switch to any other indicator by specifying the data-ss-indicator attribute to the form or button or passing the indicator class in init options.

The following example using assuming you are using Bootstrap's spinner-grow class. However you can specify you custom class to customize the process indicator animation.

Using data-ss-indicator:

<!-- Assuming you are using Bootstrap -->
<form
  data-ss-type="single-submit-form"
  data-ss-indicator="spinner-grow spinner-grow-sm">
  <!-- Your form fields here -->
  <button type="submit">Submit</button>
</form>

Using SingleSubmit.init() options:

SingleSubmit.init({
  processIndicatorClass: "spinner-grow spinner-grow-sm", // assuming you are using Bootstrap
});

To further customizing the implementation refer to configuration options.

Configuration Options

HTML Data Attributes

data-ss-type

Required with value of single-submit-form. This attribute is used to detect the forms on which to enable the single submit.

data-ss-loading-text (If set this will override the options passed through init function)

(Optional). Using this you can specify what text to show when the form is submitted and being processed. The default value is captured form the element's inner text.

data-ss-indicator If set this will override the options passed through init function

(Optional). You can set a custom processing indicator. The default value is spinner-border-single-submit which is taken inspiration from Bootstrap framework.

Init Options

Single submit offers the following options. The containerClass allows to override the default container class spinner-container-single-submit for edge cases.

interface SingleSubmitOptions {
  containerClass?: string;
  processIndicatorClass?: string;
}