title: Dynamically adding fields to simple_form with CoffeeScript
body: <p>I have a Rails 5.1.3 app that is using simple_form 3.5</p>
  
  <p>I have a <code>Books</code> table and within that a Postgres array column that holds <code>authors</code>. I've manage to build all the logic to successfully populate and save the array, however I'm struggling with dynamically adding a new author field to the form using CoffeeScript.</p>
  
  <p><code>new.html.erb</code></p>
  
  <pre><code>&lt;%= simple_form_for @book do |f| %&gt;
      &lt;%= f.input :title %&gt;
      &lt;%= f.input :subtitle %&gt;
      &lt;%= f.input :authors, as: :array %&gt;
      &lt;%= f.button :submit, "Add aditional author", class: "add-author-button" %&gt;
      &lt;%= f.input :description %&gt;
      &lt;%= f.button :submit %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><code>array_input.coffee</code></p>
  
  <pre><code>$(document).ready -&gt;
    $('.add-author-button').on 'click', @addAuthorField
  
    addAuthorField: (ev) -&gt;
      ev.preventDefault()
      $lastAuthorField = $('input[name="book[authors][]"]:last-of-type').clone()
      $lastAuthorField.val("")
      $(".text.optional.book_authors").append($lastAuthorField)
  </code></pre>
  
  <p>The problem I have is that when I click the 'Add additional author' button the form submits rather than appending a blank text field to the form. If I let the validations for the other columns fail, the form re-renders with an extra author field.</p>