Git Product home page Git Product logo

jquery.dynamiclist's Introduction

jQuery Dynamic List v2.0

A jQuery plugin that dynamically adds or removes items from a list on the client side and normalizes the list index.

This plugin is useful when data-binding one-to-many relationships. Frameworks such as Spring MVC (using AutoPopulatingList) can bind the list automatically to the form backing object as long as the items are normalized.

The idea behind this plugin is to copy the first item when adding a new item. When ever an item is added or removed, the entire list's index is normalized.

See demo page for more example such as events and call back functions.

Usage

<form>
<div id="list">
        <div class="list-item">
            <input type="text" name="guests[0].name" />
            <a href="#" class="list-remove">Remove</a>
        </div>
        <a href="#" class="list-add">Add</a>
    </div>
    <input type="submit" />
</form>

<script>
    $(document).ready(function() {
        $("#list").dynamiclist();
    });
</script>

When there are existing rows, example in Grails GSP:

<form>
    <div id="list">
        <g:each in="${guestList}" var="guest" status="i">
            <div class="list-item">
                <input type="text" name="guests[${i}].name" value="${guest.name}" />
                <a href="#" class="list-remove">Remove</a>
            </div>
        </g:each>
    <a href="#" class="list-add">Add</a>
    </div>
    <input type="submit" />
</form>

<script>
    $(document).ready(function() {
        $("#list").dynamiclist();
    });
</script>

Options

itemClass - The class name of the item in the dynamic list. Default is list-item.

addClass - The class name of the Add button. Default is list-add.

removeClass - The class name of the Remove button. Defaults to list-remove

withEvents - When cloning a new item, copy the events/listeners as well. Default is false.

minSize - The minimum number of items in the dynamic list. Default is 1.

maxSize - The maximum number of items in the dynamic list. Default is 10.

addCallbackFn - Callback function when add is completed.

removeCallbackFn - Callback function when remove is completed.

jquery.dynamiclist's People

Contributors

hungud avatar ikelin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.