All Projects → mkay581 → Form Js

mkay581 / Form Js

Licence: mit
Easily create web forms. Supports Meteor, AngularJS, React, Polymer and any CSS library, e.g. Bootstrap.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Form Js

insect
🛠 Highly customisable, minimalistic input x select field for React.
Stars: ✭ 33 (+266.67%)
Mutual labels:  input, forms, dropdown
LC-switch
Superlight vanilla javascript plugin improving forms look and functionality
Stars: ✭ 31 (+244.44%)
Mutual labels:  forms, checkbox, radio-buttons
React Menu
React component for building accessible menu, dropdown, submenu, context menu and more.
Stars: ✭ 237 (+2533.33%)
Mutual labels:  dropdown, checkbox, radio-buttons
Examples Qt
Shows how to use Qt widgets only by programming code (c++17).
Stars: ✭ 38 (+322.22%)
Mutual labels:  checkbox, radio-buttons
pretty-checkbox-react
A tiny react/preact wrapper around pretty-checkbox
Stars: ✭ 35 (+288.89%)
Mutual labels:  checkbox, radio-buttons
bootstrap5-tags
Replace select[multiple] with nices badges for Bootstrap 5
Stars: ✭ 58 (+544.44%)
Mutual labels:  input, checkbox
Validation
Framework agnostic validation library for PHP
Stars: ✭ 146 (+1522.22%)
Mutual labels:  forms, input
Examples Gtkmm
Shows how to use Gtkmm controls by programming code (c++17).
Stars: ✭ 23 (+155.56%)
Mutual labels:  checkbox, radio-buttons
hookahjs
Add empty/dirty/touched CSS hooks to input and textarea elements automatically (1056 bytes)
Stars: ✭ 21 (+133.33%)
Mutual labels:  input, forms
Examples Win32
Shows how to use Win32 controls by programming code (c++17).
Stars: ✭ 22 (+144.44%)
Mutual labels:  checkbox, radio-buttons
Ngx Treeview
An Angular treeview component with checkbox
Stars: ✭ 312 (+3366.67%)
Mutual labels:  dropdown, checkbox
Lthradiobutton
A radio button with a pretty animation
Stars: ✭ 303 (+3266.67%)
Mutual labels:  checkbox, radio-buttons
Vxe Table
🐬 vxe-table vue 表格解决方案
Stars: ✭ 4,242 (+47033.33%)
Mutual labels:  input, checkbox
svelte-multiselect
Keyboard-friendly, accessible and highly customizable multi-select component
Stars: ✭ 91 (+911.11%)
Mutual labels:  input, forms
Examples wxWidgets
Shows how to use wxWidgets controls only by programming code (c++17).
Stars: ✭ 116 (+1188.89%)
Mutual labels:  checkbox, radio-buttons
boxdetect
BoxDetect is a Python package based on OpenCV which allows you to easily detect rectangular shapes like character or checkbox boxes on scanned forms.
Stars: ✭ 46 (+411.11%)
Mutual labels:  forms, checkbox
Checkbox.css
☑️ Tiny set of pure CSS animations for your checkbox input. https://720kb.github.io/checkbox.css/
Stars: ✭ 478 (+5211.11%)
Mutual labels:  forms, checkbox
Vue Formulate
⚡️ The easiest way to build forms with Vue.
Stars: ✭ 1,947 (+21533.33%)
Mutual labels:  forms, input
Radio Group
845 byte WAI-ARIA 1.1 compliant radio group React component
Stars: ✭ 133 (+1377.78%)
Mutual labels:  forms, radio-buttons
Easy Toggle State
A tiny JavaScript library to easily toggle the state of any HTML element in any contexts, and create UI components in no time.
Stars: ✭ 261 (+2800%)
Mutual labels:  dropdown, checkbox

Build Status npm version

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. <select>, <input>, 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">Maryland</option>
    <option value="VA" selected>Virginia</option>
    <option value="DC">Washington, DC</option>
</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">Virginia</div>
        <div class="dropdown-option-container">
            <div class="dropdown-option" data-value="MD">Maryland</div>
            <div class="dropdown-option dropdown-option-selected" data-value="VA">Virginia</div>
            <div class="dropdown-option" data-value="DC">Washington, DC</div>
        </div>
    </div>
    <select>
        <option value="MD">Maryland</option>
        <option value="VA" selected>Virginia</option>
        <option value="DC">Washington, DC</option>
    </select>
</div>

Then you can style the dropdown using CSS (and just hide the <select> element).

Programmatically change the element's value

Each class comes with a set of utility methods so you can change the elements via JS. Using the example above, you could do the following:

// set the selected value programmatically
dropdown.setValue('DC');

// get the new data value
dropdown.getValue(); // => "DC"

// get the display value
dropdown.getDisplayValue(); // => "Washington, DC"

Listening to change events

You can also listen to events on form elements. Given the following input element...

<input type="text" value="" placeholder="Enter text here" />

You can do the following:

var InputField = require('form-js').InputField;
var inputField = new InputField({
    el: document.getElementsByTagName('input')[0],
    onChange: function (el) {
        // user has finished typing into the field!
    },
    onKeyDownChange: function (el) {
        // the user has typed a key into the field!
    }
});
// set the value
inputField.setValue('My text'); // set new value
// get the new value
inputField.getValue(); // => "My text"

Detect when user changes any value in a form

Suppose you have this HTML:

<form class="debt-info-form">
    <input type="text" name="first_name" value="" />
    <select name="loan_type">
        <option value="CC">Credit Card</option>
        <option value="Mortgage">Mortgage</option>
        <option value="HELO">HELO</option>
        <option value="Student Loan">Student Loan</option>
    </select>
</form>

You can detect when a user changes any of the form's elements like so:

var Form = require('form-js').Form;
var form = new Form({
    el: document.body.getElementsByClassName('debt-info-form')[0],
    onValueChange: function (val, el) {
        // a value has been changed!
       console.log('new value: ' + val);
    }
});
form.setup();

Examples

Examples can be found in the examples page.

API Documentation

Form

The form class allows you to instantiate an entire form (along with its nested elements: <input>, <textarea>, <select>).

Form.constructor

To create an instance of a form, you need to pass the form element (and a set of options if you'd like).

let formElement = document.getElementByTagName('form')[0];
var form = new Form({
   el: formElement
});

Form.setup()

Setup just does a few standard setup tasks, like bind event listeners and such. This method is necessary after instantiation in order to begin working with your form instance.

Form.getCurrentValues()

A utility method to grab a serialized object of all of the form elements and their current values. See below.

<form id="my-form">
    <input type="text" name="location" value="Arlington, VA" required />
</form>
let formElement = document.getElementById('my-form');
var form = new Form({
   el: formElement
});
form.setup();
console.log(form.getCurrentValues());

/*
[{
    disabled: false,
    name: "location",
    required: false,
    value: "Arlington, VA"
}]
*/

Form.clear()

Clears all fields inside of the form. It also unchecks any checkboxes and resets any dropdown selections.

<form id="my-form">
    <input type="text" id="location-input" name="location" value="Arlington, VA" required />
    <input type="text" id="name-input" name="name" value="John Smith" required />
    <input type="number" name="age" value="Arlington, VA" required />
</form>
let formElement = document.getElementById('my-form');
let locationInput = document.getElementById('location-input');
let nameInput = document.getElementById('name-input');
var form = new Form({
   el: formElement
});
form.setup();
locationInput.value // => "Arlington, VA"
nameInput.value // => "John Smith"
form.clear();
locationInput.value // => ""
nameInput.value // => ""

Form.disable()

Disables all form elements.

Form.enable()

Re-enables all form elements.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].