Giter Club home page Giter Club logo

jquery-sfprototypeman's Introduction

jquery.sfPrototypeMan Build Status

A jQuery plugin for the management of HTML(5) forms with the allow_add option enabled generated by Symfony 2.

Installation

Include script after the jQuery library

<script src="/path/to/jquery.sfprototypeman.js"></script>

Minified production version

This project uses Grunt. If you build it, a minified version for production usage will be created at

build/jquery.sfprototypeman.min.js

Usage

Run

jQuery().sfPrototypeMan();

to extend Symfony generated forms with collections that ("allow_add" option) offer the ability to add unknown/unlimited number of sub-forms/fields of a certain type.

By default all form parts detected to be "repeatable" as per the Symfony way of doing that, will be extended with the ability to add and remove them.

Settings

Settings can be passed to sfPrototypeMan to override the defaultOptions, e.g.

jQuery().sfPrototypeMan({
	addButtonText: "Give me one more field",
	rmButtonText: "-"
});

Events

You can attach listeners to sfPrototypeMan that will respond to events emitted by third-party code on the nodes handled by sfPrototypeMan, that is the elements with the prototype data attribute.

Default listeners

By default, sfPrototypeMan integrates with jQuery UI sortable by listening to the sortupdate event and responding respectively.

Attach more listeners

You can attach additional listeners, and thus make it integrate with third-party code in a clean fashion, like so

jQuery().sfPrototypeMan({
	containerListeners: {
		myEventName: function(event) {
			// your code reacting to myEventName
			// "this" in here will be bound to be the SfPrototypeContainer object
		}
	}
});

In this example, the event myEventName call on elements monitored by sfPrototypeMan will result in the anonymous callback function be called.

Emitted events

sfPrototypeMan emits the events prototype.elementremoved and prototype.added in the given situation.

Todo

  • bumping grunt-contrib-quint (ticket?) to >0.2.2 to get qunit >=1.10.0
  • more @todo in tests.js

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.