Dark Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

markcellus/form-js

Repository files navigation

FormJS

This library provides a simple API to manipulate a form or its related elements with JavaScript. Supports IE10+, all modern browsers, and mobile.

It's important for you to use native form elements (i.e. , etc) because they come with critical built-in logic needed for the interactions that users expect. Like tabbing to fields, pressing enter or spacebar to commit a dropdown item, mobile keyboard input triggering, etc.

Benefits

  • Automatic form data binding (JSON data and JS object literals)
  • Use CSS to easily customize hard-to-style native elements (i.e. dropdowns)
  • Listen to user events on forms
  • Easily change and update form elements and their values with JavaScript
  • Trigger events programmatically

Support

  • Checkboxes
  • Radio Buttons
  • Input Fields
  • Dropdowns (Select Elements)
  • Text Areas
  • Entire forms

Usage

You can quickly start using the Form class as a standalone package, by using one of the pre-built javascript files. Alternatively, you can also use the source files directly if you are running your own build processes.

Styling form elements

Let's say you wanted to style a dropdown menu with the following html:

<select>
<option value="MD">Marylandoption>
<option value="VA" selected>Virginiaoption>
<option value="DC">Washington, DCoption>
select>

With this library, you can do this:

var Dropdown = require('form-js').Dropdown;
var dropdown = new Dropdown({
el: document.getElementsByTagName('select')[0]
});

Which will change your HTML into this:

<div class="dropdown-wrapper">
<div class="dropdown-container">
<div class="dropdown-value-container">Virginiadiv>
<div class="dropdown-option-container">
<div class="dropdown-option" data-value="MD">Marylanddiv>
<div class="dropdown-option dropdown-option-selected" data-value="VA">Virginiadiv>
<div class="dropdown-option" data-value="DC">Washington, DCdiv>
div>
div>
<select>
<option value="MD">Marylandoption>
<option value="VA" selected>Virginiaoption>
<option value="DC">Washington, DCoption>
select>
div>

Then you can style the dropdown using CSS (and just hide the ,