Skip to content

Instantly share code, notes, and snippets.

@julianalucena
Created December 24, 2011 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julianalucena/1516092 to your computer and use it in GitHub Desktop.
Save julianalucena/1516092 to your computer and use it in GitHub Desktop.
jQuery ($) ->
# Options for deeper nested fields
resourcesOptions = {
itemSelector: ".resource",
containerSelector: ".resources-container",
addSelector: ".resource-add",
removeSelector: ".resource-remove",
itemTemplateSelector: ".resource.template", # Identifies which template to use
new_item_index: "new_resource_index" # Same used on view options
}
# Apply nestedFields to the outsider nested fields (first nested fields level)
$(".project-form").nestedFields({
itemSelector: ".task",
containerSelector: ".tasks-container",
addSelector: ".task-add",
removeSelector: ".task-remove",
itemTemplateSelector: ".task.template",
new_item_index: "new_task_index",
afterInsert: (item) ->
# Applies nestedFields to this task's resources (deeper field)
item.find(".nested-level-2").nestedFields(resourcesOptions)
# Inserts a resource item (of the deeper field)
item.find(".nested-level-2").nestedFields("insert")
})
# Applies nestedFields to all projects on page (to the second nested fields level)
$(".project-form").find(".nested-level-2").nestedFields(resourcesOptions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment