RailsCasts Pro episodes are now free!

Learn more or hide this

Lev Brie's Profile

GitHub User: levbrie

Comments by Lev Brie


This is the default behavior when clicking on a link with an href="#". Make sure that whatever javascript your using to add or remove fields includes an event.preventDefault() call. In coffeescript, this should look something like the following for nested fields but can easily be applied to any click event where you need to suppress the default behavior for a given event:

jQuery ->
  $('form').on 'click', '.remove_fields', (event) ->

  $('form').on 'click', '.add_fields', (event) ->
    time = new Date().getTime()
    regexp = new RegExp($(this).data('id'), 'g')
    $(this).before($(this).data('fields').replace(regexp, time))