Skip to content

A jQuery plugin extending Symfony 2 generated 'allow_add' HTML(5) forms.

License

Notifications You must be signed in to change notification settings

maltestenzel/jquery-sfPrototypeMan

 
 

Repository files navigation

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

About

A jQuery plugin extending Symfony 2 generated 'allow_add' HTML(5) forms.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 86.4%
  • HTML 13.6%