Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Add and remove nested model fields dynamically through JavaScript using jQuery

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 vendor
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 ajax_nested_form.gemspec
README.md

AjaxNestedForm

This gem provides adding and removing nested model fields dynamically through JavaScript using jQuery. It may using for Rails 3.1+ with assets pipeline

Installation

Add this line to your application's Gemfile:

gem 'ajax_nested_form'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ajax_nested_form

Usage

Javascript

Add necessary javascript file to app/assets/javascripts/application.js

//= require ajax_nested_form

Using ActionView helper methods

For creating link to add nested model fields use next syntax

link_to_add_fields "LinkText", form_builder_instance, :association_name, "container_for_adding_fields", "position_for_adding"

Available positions for adding are "first" and "last". Last is used by default.

Sample

link_to_add_fields "Add list", f, :lists, "#lists-container", "first"

For creating link to destroy nested model fields use following code

link_to_remove_fields "Remove", form_builder_instance, "nested_model_fields_container"

Sample

link_to_remove_fields "Remove", f, ".list-fields"

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Something went wrong with that request. Please try again.