Sha256: bbec47aaa2cca5331a3350dbfc0ff477fe0fee9e2c27457fff8ee4b779655668

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

jQuery ->

  $('body').on 'click', '.add_nested_fields_link', ->
    $link = $(this)
    association_path = $link.data('association-path')
    $template = $("##{association_path}_template")

    template_html = $template.html()

    # insert association indexes
    index_placeholder = "__#{association_path}_index__"
    template_html = template_html.replace(new RegExp(index_placeholder,"g"), $(".nested_#{association_path}").length)

    # replace child template div tags with script tags to avoid form submission of templates
    $parsed_template = $(template_html)
    $child_templates = $parsed_template.children('.form_template')
    $child_templates.each () ->
      $child = $(this)
      $child.replaceWith($("<script id='#{$child.attr('id')}' type='text/html' />").html($child.html()))

    $link.before( $parsed_template )
    false


  $('body').on 'click', '.remove_nested_fields_link', ->
    $link = $(this)
    delete_association_field_name = $link.data('delete-association-field-name')
    $nested_fields_container = $link.parents(".nested_fields").first()
    $nested_fields_container.before "<input type='hidden' name='#{delete_association_field_name}' value='1' />"
    $nested_fields_container.hide()
    false

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nested_form_fields-0.0.3 vendor/assets/javascripts/nested_form_fields.js.coffee
nested_form_fields-0.0.2 vendor/assets/javascripts/nested_form_fields.js.coffee
nested_form_fields-0.0.1 vendor/assets/javascripts/nested_form_fields.js.coffee