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

elo7-form-amd

v1.1.1

Published

A small library to help form manipulations and validation

Downloads

3

Readme

Form-amd

Form-amd library

form.js is a small library to help form manipulations and validation. This library uses amd structure.

Build Status

It uses html5 form attributes validate specification and works on browsers that does not support html5 validation. Then, we built it from scratch.

Installation

Install with npm: npm install elo7-form-amd

Dependencies

Form-amd depends on an amd implementation. We suggest async-define implementation for dependency lookup. Form-amd also depends on doc-amd.

Methods

submitOnChange

.submitOnChange(selectorOrDocElement[, callback])

Description:

Submit the parent form when event change is triggered.

Parameters:

selectorOrDocElement: doc-amd object or String //A CSS selector. Note that, if it is a class name with dots, the dots must be escaped. E.g.: doc(".my\\.class")

callback: Function() //A function to call before the event is triggered

Sample:
define(['form'], function(form) {
  form.submitOnChange($('#country')); //Submit the parent form when the country is selected
  form.submitOnChange('#country', function(){...}); //Run the callback function and then submit the parent form when the country is selected
});

submitOnBlur

.submitOnBlur(selector)

Description:

Submit the parent form when event blur is triggered.

Parameters:

selector: String

Sample:
define(['form'], function(form) {
  form.submitOnBlur('#name'); //Submit the parent form when the form element loses focus
});

focus

.focus(selector)

Description:

Focus on selected element. If the device is mobile, it calls scrollIntoView function.

Parameters:

selector: String

Sample:
define(['form'], function(form) {
  form.focus('#input'); //Focus on the element #input
});

validate

.validate(selectorOrDocElement[, object])

Description:

Validate the form using almost all the html5 attributes validate spec.

Parameters:

selectorOrDocElement: doc-amd object or String //A CSS selector. Note that, if it is a class name with dots, the dots must be escaped. E.g.: doc(".my\\.class")

object: Object //An object with the properties messages ("required", "min", "maxlength", "pattern" or "email"), success (function callback) or error (function callback)

Sample:
define(['form'], function(form) {
  form.validate($('#form')); //Validate the form with default messages
  form.validate('#form', {
    messages: {
      'required': 'Field required.',
      'min': 'Enter a value greater than or equal to {0}.',
      'maxlength': 'Enter a value with max length less than or equal to {0}.',
      'pattern': 'Enter a valid value.',
      'email': 'Enter a valid email address.'
    }, //Validate the form with this messages
    success: function(){
      // success callback
    },
    error: function(){
      // error callback
    }
  });
});
Default messages:
 required: This field is required
 min: Please enter a value greater than or equal to {0}
 maxlength: Please enter a value with max length less than or equal to {0}
 pattern: Please enter a valid value
 email: Please enter a valid email address

appendMessage

.append(selector, text)

Description:

Append validation messages

Parameters:

selector: String

text: String

Sample:
define(['form'], function(form) {
  form.append('label[for="date"]', 'dd/mm/yyyy'); //This will append <span class="message">dd/mm/yyyy</span>. Note that this element will be removed when the user starts to type another value.
});

removeValidationErrors

.removeValidationErrors(selector)

Description:

Removes all validation messages from selected form

Parameters:

selector: String

Sample:
define(['form'], function(form) {
  form.removeValidationErrors('#form'); //This will remove all validation messages appended
});

License

Form-amd is released under the BSD. Have at it.


Copyright :copyright: 2019 Elo7# form-amd