8000 GitHub - dominicbarnes/form: A helper for working with HTML forms · GitHub
[go: up one dir, main page]

Skip to content
dominicbarnesPublic

About

A helper for working with HTML forms

Resources

Stars

7 stars

Watchers

1 watching

Forks

Latest commit

 

History

35 Commits

Folders and files

Repository files navigation

form

A helper for working with HTML forms, contains the functionality of:

all wrapped up in a nice package.

Usage

<form id="my-form">
    <input type="hidden" name="id" value="123456">
    <input type="text" name="user.name" value="dominicbarnes">

7249
    <input type="url" name="user.website" value="http://dbarnes.info/">
</form>
var Form = require("form");
var el = document.querySelector("#my-form");

var form = new Form(el);

form.input("id");
// => <input type="hidden" name="id" value="123456">

form.serialize();
// => { id: "123456", user: { name: "dominicbarnes", website: "http://dbarnes.info" } }

form.value("user.name");
// => "dominicbarnes"

form.value("id", "abc123");
// sets "abc123" as the value for the "id" input

API

Form(el)

Creates a new wrapper (new keyword not required) for the input el (should be an HTMLFormElement)

Form#input(name)

Returns the form element(s) with the supplied name. (see dominicbarnes/form-element)

Form#value(name, val)

Gets or sets the value for the input matching name (see component/value)

NOTE: This method does not currently support checkboxes or radio groups.

Form#serialize()

Serializes the entire form into a single JS object. (see dominicbarnes/form-serialize)

Form#classes

A CSS class helper via component/classes.

About

A helper for working with HTML forms

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

0