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

jquery-toggle-fields

v3.4.3

Published

Adds form conditions to show and hide form fields.

Downloads

2

Readme

jQuery Toggle fields

Adds logic to disable and enable form fields.

The plugin simply:

  • Adds/ removes a disabled class to textual elements;
  • Adds/ removes a disabled class & disabled attribute to input elements.

Usage

To get started you can:

  • Clone the repo: git clone https://github.com/nomensa/jquery.toggle-fields.git

Then it's just a case of including the following scripts on your page, best at the bottom:

  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <script src="jquery.toggleFields.js"></script>

DOM requirements

|Attribute|Value|Explanation|Required| |--- |--- |--- |--- | |data-toggle-conditions|#field-1-with-condition, #field-2-with-condition|A condition is a form field that triggers the toggle. This represents a jQuery selector. Multiple conditions must be separated with a comma and space.|Required| |data-toggle-target|None|The individual element to be toggled. Expected form field or textual element.|Required| |data-toggle-next|None|Required if using multiple conditions. Used on the wrapping element of the targets.|Required| |data-toggle-ref|#field-1-with-condition|Required if using multiple conditions. Used on the wrapping element of the targets. Matches the ID in the 'data-toggle-conditions' attribute.|Required| |data-toggle-recursive|none|Required if using recursive conditions. Used to identify a recursive condition; one that relies on another condition.|Required|

DOM requirement examples

data-toggle-conditions
    <div data-toggle-conditions="#field-1-with-condition, #field-2-with-condition">
data-toggle-target
    <label data-toggle-target for="field-1-with-condition-example"> Label for a form field </label>
    <input data-toggle-target id="field-1-with-condition-example"/>
data-toggle-next & data-toggle-ref
   <div data-toggle-next data-toggle-ref="field-1-with-condition"> The wrapping element of the targets </div>
data-toggle-recursive
   <div data-toggle-next data-toggle-ref="field-2-with-condition" data-toggle-recursive> The wrapping element of the targets </div>

Options

|Option|Default|Explanation| |--- |--- |--- | |conditionIdentifier|'data-toggle-condition'|(attribute) Used to identify the element with the condition| |conditionsIdentifier|'data-toggle-conditions'|(attribute) Used to identify all conditions in the DOM| |disabledClass|'disabled'|(class) The class added for the disabled state| |disabledAttr|'disabled'|(attribute) The disabled attribute added on form elements| |helpTextIdentifier|'form-row__instructions'|(class) Used to identify any additional text related to the targets| |nextFormRowsIdentifier|'data-toggle-next'|(attribute) Used to identify the wrapper for the targets| |nextRowReferenceIdentifier|'data-toggle-ref'|(attribute) Used to identify the condition in which the wrapper belongs to| |targetIdentifier|'data-toggle-target'|(attribute) Used to identify the targets for the conditions| |toggleClass|'js-toggleFields--on'|(class) Identifies whether the toggle has applied' |toggleClass|js-toggleFields--on|(class) Represents toggled state, used on the target container| |initCallback|function(){}|Callback when initialised| |toggleOnCallback|function(){}|Callback when toggled on| |toggleOffCallback|function(){}|Callback when toggled off|

Init

    $('form').toggleFields();

Init with options

    var options = {
        conditionIdentifier: 'data-toggle-condition',
        conditionsIdentifier: 'data-toggle-conditions',
        disabledClass: 'disabled',
        disabledAttr: 'disabled',
        helpTextIdentifier: 'form-row__instructions',
        nextFormRowsIdentifier: 'data-toggle-next',
        nextRowReferenceIdentifier: 'data-toggle-ref',
        targetIdentifier: 'data-toggle-target',
        toggleClass: 'js-toggleFields--on'
        initCallback: function initCallback() {},
        toggleOnCallback: function toggleOnCallback() {},
        toggleOffCallback: function toggleOffCallback() {}
    };

    $('form').toggleFields(options);

Examples

See index.html for examples.

Development

To ensure test suites continue to work while developing, this plugin requires:

Node

First time setup of this plugin will require the node packages to be installed.

If you have NVM installed, make sure to use the correct node version:

$ nvm use 0.10

Next install the plugin's node packages:

$ npm install

Grunt

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to install and use Grunt.

You will need to install the Grunt CLI (command line interface):

$ npm install -g grunt-cli
# => if you have used grunt before you probably have this (this can be run from any directory)

Running

We use http-server to serve the demo page:

$ http-server

Testing

We use Karma to build the test suites, which in turn uses Jasmine.

# Run Karma:
$ npm test

The Jasmine file is jquery.toggleFields.spec.js.

The test coverage is then compiled in the coverage folder. Inside the coverage folder, open the PhantomJS 1.9.8 (Linux 0.0.0) folder to see the latest test coverage.

Browser support

Below is a list of browsers the plugin supports, however you may find it works in older version of browsers.

  • IE v.7+;
  • FF latest;
  • Chrome latest;
  • Opera latest;
  • Safari latest.

Todo

No tasks currently in our todo list.

Copyright © 2017 @nomensa Licensed under MIT