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.repeatable

v0.4.1

Published

A jQuery plugin that allows you to easily create repeatable groups of form fields.

Downloads

495

Readme

jquery.repeatable.js

A jQuery plugin that allows you to easily create repeatable groups of form fields.

Getting started

Markup

At a bare minimum, the html form should contain a container for which the repeatable items will populate and a button that when clicked, tells jquery.repeatable to add another item. The classes you use can be different than the example below, but make sure you register any differences when you call the plugin. See settings below.

<form>
  <div class="repeatable-container"></div>
  <input type="button" value="Add Person" class="add" />
  <input type="submit" value="Submit" />
</form>

Field group template

The field group template contains html for the group of form fields that will be repeatable. Here are a few things to keep in mind:

  • The form fields need to be within a container element.
  • Include the symbol {?} when you need a unique value. You must at least include this symbol in the name attribute of your form fields to ensure they are all unique.
  • If you want users to be able to delete items, include a delete button in the template.
<script type="text/template" id="people">
<div class="field-group">
  <label for="firstname_{?}">First name</label>
  <input type="text" name="firstname_{?}" value="" id="firstname_{?}" />

  <label for="lastname_{?}">First name</label>
  <input type="text" name="lastname_{?}" value="" id="lastname_{?}" />

  <input type="button" class="delete" value="X" />
</div>
</script>

JavaScript

The following JavaScript can be used in conjunction with the form and template shown above.

$(function() {
  $("form .repeatable-container").repeatable({
    template: "#people"
  });
});

When a user clicks on the .add button, the script will render a new .field-group within the .repeatable-container. Each {?} will be replaced with a unique value so that each field is unique in the scope of the form. If a user clicks on a .delete button within a group, that group will be removed from the form.

Settings

  • addTrigger: Optional. (string) The selector that when clicked, a new field group will be added to the repeatable item container. Default: ".add"
  • deleteTrigger: Optional. (string) The selector that when clicked, the field group the delete selector is within will be removed from the form. Default: ".delete"
  • itemContainer: Optional. (string) The selector that represents each field group container. Default: ".field-group"
  • max: Optional. (integer) The maximum number of field group elements that may be added to the repeatable item container. Default: null.
  • min: Optional. (integer) The minimum number of field group elements that may be present in the repeatable item container. The form is prepopulated with this amount of field group elements. Default: 0.
  • beforeAdd: Optional. (function) A function to run before an item is added to the repeatable item container. Default: none
  • afterAdd: Optional. (function (addedItem)) A function to run after an item is added to the repeatable item container. Default: none
  • beforeDelete: Optional. (function (itemToDelete)) A function to run before an item is deleted from the repeatable item container. Default: none
  • afterDelete: Optional. (function) A function to run after an item is deleted from the repeatable item container. Default: none
  • template: Required. (string) The selector that contains the form field group template.