Sha256: 5fa75b034d364fa849b6febc72b925fa9c2023badc707fe7099a989da78f0e2e

Contents?: true

Size: 729 Bytes

Versions: 2

Compression:

Stored size: 729 Bytes

Contents

$ ->
  $(document).off 'click', 'form .remove_fields'
  $(document).off 'click', 'form .add_fields'

  $(document).on 'click', 'form .remove_fields', (event) ->
    $(this).prev('input[type=hidden]').val('1')
    $(this).closest('.fields').hide()
    $(document).trigger('dynamicFieldsFor.remove', @)
    event.preventDefault()

  $(document).on 'click', 'form .add_fields', (event) ->
    time = new Date().getTime()
    regexp = new RegExp($(this).data('id'), 'g')
    $target = $($(@).data('target'))
    fields = $(this).data('fields').replace(regexp, time)
    if $target.length
      $target.append(fields)
    else
      $(this).before(fields)
    $(document).trigger('dynamicFieldsFor.add', @)
    event.preventDefault()

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dynamic_fields_for_rails-0.6.0 app/assets/javascripts/dynamic_fields_for.coffee
dynamic_fields_for_rails-0.5.3 app/assets/javascripts/dynamic_fields_for.coffee