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

@evanminto/async-form

v0.2.5

Published

Transforms normal HTML forms into asynchronous forms, replacing normal submission with a AJAX requests.

Downloads

3

Readme

async-form v0.2.5

Transforms normal HTML forms into asynchronous forms, replacing normal submission with a AJAX requests.

How to Use

The module exposes a function "asyncForm" that accepts various arguments representing a form or forms that should be turned into asynchronous forms. Once the function initializes the form, all subsequent submit events on the form will result in AJAX calls instead of normal form submissions. The method, action, and other parameters are determined by the properties of the form element and its children.

NOTE: Calling the native HTMLFormElement.submit() method does not trigger the submit event, so that function will still trigger a normal, synchronous submission.

Node

  const asyncForm = require('@evanminto/async-form'); // Not published to NPM yet!

  asyncForm(document.querySelector('#my_form'));
  asyncForm(document.querySelectorAll('.my-form'));
  asyncForm('.my-form');

Browser

  window.asyncForm(document.querySelector('#my_form'));
  window.asyncForm(document.querySelectorAll('.my-form'));
  window.asyncForm('.my-form');

Functions

asyncForm(target)

Intercepts all future submit events on the specified target element(s), replacing normal form submission with an AJAX request.

Arguments:

  • target is one of the following:
    • HTMLFormElement: a form element
    • NodeList: a list of form elements
    • String: a CSS selector representing one or many form elements

asyncForm.submit(form)

Gathers data from a form element and submits it via an AJAX request. This method is useful if you would like more fine-grained control over when your form submits its data.

Arguments:

  • form is an HTMLFormElement

Events

During submission, the form dispatches a number of custom events representing different steps in the submission process. All events have an "asyncForm" namespace.

error.asyncForm

Cancelable: false

Dispatches when the form has failed to send the AJAX request. This is usually because of network failure or some other fundamental problem.

fail.asyncForm

Detail Property Contains: response (Response) Cancelable: false

Dispatches when the form has finished sending the AJAX request and received a response outside of the successful 200 range of status codes.

submitted.asyncForm

Detail Property Contains: response (Response) Cancelable: false

Dispatches when the form has finished sending the AJAX request and received a response (regardless of the status code of the response).

submitting.asyncForm

Detail Property Contains: request (Request) Cancelable: true

Dispatched when the form is about to send the AJAX request. If canceled, the form does not send the request.

success.asyncForm

Detail Property Contains: response (Response) Cancelable: false

Dispatches when the form has finished sending the AJAX request and received a response with a successful (>= 200, < 300) status code.

Data Attributes

Data attributes enable customization of the request properties for AJAX requests sent by the form. All data attributes must be attached to the form element and are prefixed with async-form.

data-async-form-accept

Sets the value of the Accept header on the AJAX request. If not provided, the request will set no explicit Accept header.

data-async-form-credentials

Sets the value of the credentials property of the AJAX request. If not provided, defaults to "omit," as defined in the Fetch API spec.

data-async-form-mode

Sets the value of the mode property of the AJAX request. If not provided, defaults to "no-cors," as defined in the Fetch API spec.