Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

How To: Add multiples fields with one click

Gabriel edited this page Mar 2, 2015 · 3 revisions

Using javascript events you could add multiple fields with one click, e.g. add 3 fields at once:

jQuery(function ($) {
  $(document).on('nested:fieldAdded', function (event) {
    for (var n = 2; n; n--) {
      event.field.clone().insertAfter(event.field);
    }
  });
});

this way can create multiple fields , but the fields have the same index value , that's not what I need , instead , I read the code and use this line , that works

$(function(){
    for (var n = 2; n; n--) {
        $(document).delegate('form a.add_nested_fields',    'click', nestedFormEvents.addFields)
    }
})