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

web-form-helper

v1.0.3

Published

npm install web-form-helper # API ## onSubmit |argument|type |--|-- |callback|(obj: `Object`or `FormData`) => `FormEventFunction` |options|`ISubmitOptions`or `undefined`

Downloads

11

Readme

Install

npm install web-form-helper

API

onSubmit

|argument|type |--|-- |callback|(obj: Objector FormData) => FormEventFunction |options|ISubmitOptionsor undefined

type

|name|values|types|descriptions |--|--|--|-- |ISubmitOptions| {} ||isExcuteDefault|boolean or undefined| Indicates whether to execute an action that is basically hanging on the event. The default is false. ||validate|(validateParameter: T) => string or IFailValidateReturnType or undefined| Write a logic that verifies yourself. Return the name of the part where the verification error occurs, or return according to the IFailValidateReturnType. If there is none, do not return. ||onInvalid|(targetInvalidElement?: HTMLElement, invalidData?: IFailValidateReturnType or string) => void|If there is anything returned from the validate, it will be executed. |IFailValidateReturnType|{}|Object|I'm the type to return on the validate. ||name|string|validate 오류가 발생한 input의 name으로 필수 입니다. ||message|string or undefined|validate 오류가 발생 할 때, 추가적으로 메세지를 작성해서 return 합니다. 기본은 undefined입니다. ||index|number or undefined|validate This is a field that tells you which number occurred if there is the same name among the inputs where the error occurred. The default is zero.

Input description

|input-type|Object-value-type| |--|--| |date| Date |datetime or datetime-local|Date |number|number |checkbox|Array<string> |file|File |range|number |radio|string |etc...|string

onInvalid

|argument|type |--|-- |callback|(failTarget?: HTMLElement, reason: failReason?: "valueMissing" or "valid" or "typeMismatch" or "tooShort" or "tooLong" or "rangeUnderflow" or "rangeOverflow" or "badInput" or "customError" or "patternMismatch") => void |options|IInvalidOption or undefined

type

|name|values|types|descriptions |--|--|--|-- |IInvalidOption|{} ||isExcuteDefault|boolean or undefined|Indicates whether to execute an action that is basically hanging on the event. The default is false.

Examples

React


import React from 'react';
import { onSubmit } from 'web-form-helper';

function App() {
  const onSubmit = (data) => console.log(data);
  return (
    <form onSubmit={onSubmit(onSubmit)}>
      <input name="firstname" />
      <input name="lastname" />
      
      <input name="age" type="number" />
      <button htmlType="submit">submut</button>
    </form>
  );
}

PLAIN HTML && PLAIN JS

--- html ---
<html>
  <body>
    <form id="form">
      <input name="firstname" />
      <input name="lastname" />
      
      <input name="age" type="number" />
      <button htmlType="submit">submut</button>
    </form>
    <script src="index.js"></script>
  </body>
</html>
--- index.js ---
import { onSubmit, onInvalid } from 'web-form-helper';

var form = document.getElementById("form");

function objSubmitListener(param) {
	console.log(param)
}

function invalidListener(failElement, reason) {
	console.log(failElement, reason);
}

form.addEventListener("submit", onSubmit(objSubmitListener), false)

form.addEventListener("invalid", onInvalid(invalidListener), { capture: true })

Validate Examples

import { onSubmit, onInvalid } from 'web-form-helper';

var form = document.getElementById("form");

function objSubmitListener(param) {
	console.log(param)
}

function invalidListener(failElement, reason) {
	console.log(failElement, reason);
}

function submitValidate(obj) {
	// Please return the information about the part where the verification error occurs.
	// if not error return undefined or null or void
	if (obj.number[0] <= 2) return { name: "number", index: 0, message: "The first number must be greater than 2." };
	if (obj.number[1] <= 4) return { name: "number", index: 1, message: "The second number must be greater than 4." };
	if (obj.number[0] >= obj.number[1]) return { name: "number", message: "The first number should be less than the second number." }
	if (obj.textName.length === 0) return "textName";
}

function submitInvalid(element, invalidData) {
	if (invalidData.message) {
		alert(invalidData.message);
	}

	if (invalidData === "textName") {
		alert("The textName length must be greater than 0.")
	}

	element.style.border = "1px solid red";
}

form.addEventListener("submit", onSubmit(objSubmitListener, { validate: submitValidate, onInvalid: submitInvalid }), false)

form.addEventListener("invalid", onInvalid(invalidListener), { capture: true })