Code Monkey home page Code Monkey logo

h5f's Introduction

H5F

a JavaScript library that allows you to use the HTML5 Forms chapters new field input types, attributes and constraint validation API in non-supporting browsers.

The H5F script will detect if the browser has support for the HTML5 Forms Chapter and either hook into the native methods, attributes and events or emulate the new features in non-supporting browsers.

What's supported

H5F offers support for most, but not all, of the HTML5 Forms Chapter:

  • Input types: email and url
  • Input attributes: pattern, placeholder, min, max, step, required
  • Textarea attributes: placeholder and required
  • Select attributes: required

Also supported is the constraint validation API:

  • Field validity object
  • checkValidity() method on form or indivdual field

Example

<form id="signup">
    <label>Email</label>
    <input type="email" placeholder="e.g. [email protected]" required />

    <label>Phone</label> 
    <input type="tel" id="tel" name="tel" pattern="\d{10}" />

    <label>Post code *</label>
    <input type="number" min="1001" max="8000" required />

    <input type="submit" />
</form>

On page load you run the H5F setup method:

H5F.setup(document.getElementById("signup"));

For a working demo download the demo files.

Passing multiple forms

You can pass a HTMLFormElement, HTMLCollection of HTMLFormElements, or Array of HTMLFormElements.

H5F.setup([document.getElementById("form1"),document.getElementById("form2"),document.getElementById("form3")]);

Optional settings argument

The H5F.setup method also accepts a second optional argument so you can specify the fields validation class names:

H5F.setup(document.getElementById("signup"), {
    validClass: "valid",
    invalidClass: "invalid",
    requiredClass: "required"
});

http://thecssninja.com/javascript/H5F

Dual-licensed under the BSD and MIT licenses.

h5f's People

Contributors

cgunther avatar ryanseddon avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.