All Projects → muicss → hookahjs

muicss / hookahjs

Licence: MIT license
Add empty/dirty/touched CSS hooks to input and textarea elements automatically (1056 bytes)

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to hookahjs

insect
🛠 Highly customisable, minimalistic input x select field for React.
Stars: ✭ 33 (+57.14%)
Mutual labels:  input, forms
Awesomevalidation
Android validation library which helps developer boil down the tedious work to three easy steps.
Stars: ✭ 1,093 (+5104.76%)
Mutual labels:  input, forms
Form Js
Easily create web forms. Supports Meteor, AngularJS, React, Polymer and any CSS library, e.g. Bootstrap.
Stars: ✭ 9 (-57.14%)
Mutual labels:  input, forms
Autosize Input
🎈 Effortless, dynamic-width text boxes in vanilla JavaScript
Stars: ✭ 64 (+204.76%)
Mutual labels:  input, forms
Vue Formulate
⚡️ The easiest way to build forms with Vue.
Stars: ✭ 1,947 (+9171.43%)
Mutual labels:  input, forms
Input Value
React hook for creating input values
Stars: ✭ 104 (+395.24%)
Mutual labels:  input, forms
Customui
Library to create custom UI's in MCPE 1.2+
Stars: ✭ 60 (+185.71%)
Mutual labels:  input, forms
Validation
Framework agnostic validation library for PHP
Stars: ✭ 146 (+595.24%)
Mutual labels:  input, forms
svelte-multiselect
Keyboard-friendly, accessible and highly customizable multi-select component
Stars: ✭ 91 (+333.33%)
Mutual labels:  input, forms
tags
HTML tags in Go
Stars: ✭ 50 (+138.1%)
Mutual labels:  forms
reCAPTCHA
‼️ Google reCAPTCHA (security) for Nette Framework \ Forms
Stars: ✭ 35 (+66.67%)
Mutual labels:  forms
SheenValidator
Android library to make form validation easier
Stars: ✭ 29 (+38.1%)
Mutual labels:  input
django-siteforms
Django reusable app to simplify form construction
Stars: ✭ 15 (-28.57%)
Mutual labels:  forms
municipios-br
Dados em formato aberto sobre municípios e unidades federativas do Brasil.
Stars: ✭ 58 (+176.19%)
Mutual labels:  forms
rci
🔢 better code inputs for react/web
Stars: ✭ 805 (+3733.33%)
Mutual labels:  input
react-native-input-prompt
A cross-platform user input prompt component for React Native with Native UI.
Stars: ✭ 45 (+114.29%)
Mutual labels:  input
react-file-input-previews-base64
This package provides an easy to use, ready to go and customizable wrapper around file input, with option for image previews and returning file as base64 string.
Stars: ✭ 15 (-28.57%)
Mutual labels:  input
kindaVim.theapp
Ultimate Vim Mode for macOS
Stars: ✭ 372 (+1671.43%)
Mutual labels:  input
rich input
Rich input box, implement @Someone and subject with color highlighting
Stars: ✭ 58 (+176.19%)
Mutual labels:  input
activeadmin-ajax filter
AJAX filters for ActiveAdmin
Stars: ✭ 86 (+309.52%)
Mutual labels:  input

HookahJS

HookahJS is a tiny JavaScript library that monitors all input and textarea elements on your page and adds empty/dirty/touched CSS hooks to each element automatically.

Introduction

HookahJS is a tiny JavaScript library that monitors all input and textarea elements on your page and adds the following CSS classes in response to user interactions with each element:

  • hkjs--empty - control element is empty
  • hkjs--not-empty - control element is not empty
  • hkjs--pristine - control element has not seen an input or change event
  • hkjs--dirty - control element has seen an input or change event
  • hkjs--untouched - control element has not seen a blur event
  • hkjs--touched - control element has seen a blur event

HookahJS uses CSS @keyframes to detect new DOM elements so once the library is loaded, it will automatically add CSS hooks to new input and textarea elements. HookahJS is 1056 bytes (minified + gzipped).

Quickstart

To use HookahJS you only need to add hookah.js to your page and the library will automatically add event listeners to all current and future input and textarea elements. The following example will draw a red box around an invalid input box after the user has touched the element:

<!doctype html>
<html>
  <head>
    <script src="//cdn.rawgit.com/muicss/hookahjs/0.0.6/dist/hookah.min.js"></script>
    <style>
      .hkjs--touched:not(:valid) {
        border: 1px solid red;
      }
    </style>
  </head>
  <body>
    <input type="text" required>
    <input type="email" required>
  </body>
</html>

View Demo »

HookahJS uses CSS @keyframes to detect new DOM elements so once the library is loaded, it will automatically add CSS hooks to new input and textarea elements.

Browser Support

  • IE10+
  • Opera 12+
  • Safari 5+
  • Chrome
  • Firefox
  • iOS 6+
  • Android 4.4+

Note: HookahJS uses CSS @keyframes to detect new DOM elements automatically. To use HookahJS in IE9 you can initialize DOM elements explicitly with hkjs.init().

Documentation

How to load HookahJS

For production systems we recommend that you host the library file yourself which you can download from the dist/ directory in this repository:

For tighter integration with your code you can also use the HookahJS NPM package:

$ npm install --save hookahjs
var hkjs = require('hookahjs');

document.addEventListener('DOMContentLoaded', function() {
  hkjs.init();
});

HookahJS can be loaded asynchronously but keep in mind that if HookahJS is initialized after the DOM content has been displayed to the user, there may be a flash of unstyled content. To avoid this you can seed your page with .hkjs--empty/.hkjs--not-empty classes as necessary.

How to initialize elements selectively

By default, HookahJS will add event listeners to all current and future input and textarea elements. To prevent this behavior you can listen to the hkjs-init event and call the preventDefault() method on the event object. You can also use the hkjs global object to add hooks to individual elements:

window.addEventListener('hkjs-init', function(ev) {
  // prevent HookahJS from adding hooks to all <input> and <textarea> elements
  ev.preventDefault();

  // use the `hkjs` global object to add hooks to elements manually
  var inputEl = document.getElementById('my-input-element');
  hkjs.init(inputEl);
});

How to handle programmatic updates

HookahJS can detect all change and input events triggered by user interactions but it can't detect programmatic changes to control elements. To update the HookahJS CSS classes after making a programmatic change to a control element, you can trigger a change or input event on the element:

// modify element
var inputEl = document.getElementById('my-input-element');
inputEl.value = 'Programmatic input';

// initialize event object (with bubbles = false)
var ev = document.createEvent('HTMLEvents');
ev.initEvent('change', false);

// trigger event
inputEl.dispatchEvent(ev);
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].