npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

heidi

v1.0.0

Published

Hides and shows elements dependent on form input

Downloads

2

Readme

Heidi -- makes forms more interactive

Heidi is a tiny JavaScript library that shows or hides content areas according to user interaction on form elements. You only need to use data-attributes in HTML.

See the demo on www.woerter.de/projects/heidi/demo.html and check out its source code which is part of this repository.

Installation

  1. Embed jQuery (tested with v2, will possibly work with v1).
  2. Embed heidi.js. You can do that in the head or anywhere in the body, as you prefer.
  3. Embed heidi.css which contains a few necessary CSS classes.

Your header might look like this:

<head>
    <meta charset="utf-8">
    <title>I contain an interactive form</title>
    <link rel="stylesheet" type="text/css" href="heidi.css"/>
    <script type="text/javascript" src="vendor/jquery2.js"></script>
    <script type="text/javascript" src="heidi.js"></script>
</head>

Basic Usage:

  • Set a data-select attribute in a form element. Its value has to be a CSS selector as you use them in jQuery, e.g. data-select="#element" or data-select=".class".
  • All elements which fit to this selector will be hidden onLoad and show up when you enter content, select or check the form element – depending on the type of the form element.
  • Heidi works with <input> (all types), <option>, and <button>.
  • Heidi is tested on all modern browsers and Internet Explorer back to version 9. It possibly will work on even older IEs, but go check yourself if you have to.
  • There is basic support for <textarea> but browsers don't handle onChange events on these elements very well. Heidi does not yet make use of onInput.

Some Advanced Tips:

  • If you hide other form elements you can decide if you want their contents deleted if they are hidden (default: no). Set the property deleteHiddenFields in the beginning of the script accordingly.
  • You can use complex selectors. <input type="checkbox" data-select=".class, #id"/> will turn on <x id="id"> and all <x class="class">.
  • Negative selectors are possible! <input type="checkbox" data-select="!.class"/> will turn off all
  • If you need more than one condition to be met for an element to show, use different selectors, e.g. #id and el#id.
  • Buttons are different from input and select fields. They are meant to be used as a row of switches turning alternate sections of content on (see demo below). They require a data-value attribute in their root element that states which section is on per default. They can't have multiple selectors.