I see, that makes sense


On Sun, Nov 3, 2013 at 1:57 PM, Sean Linsley <notifications@github.com>wrote:

> In app/assets/javascripts/active_admin/components/has_many.js.coffee:
>
> > @@ -0,0 +1,17 @@
> > +unescape_html = (html)->
> > +  String(html).replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g,'>').replace(/&quot;/g, '"').replace(/&#x27;/g, "'")
> > +
> > +$ ->
> > +  $(document).on 'click', 'a.button.has_many_remove', (e)->
> > +    e.preventDefault()
> > +    $(@).closest('.has_many_fields').remove()
> > +
> > +  $('a.button.has_many_add').click (e)->
> > +    e.preventDefault()
> > +    $(@).trigger 'has_many_add:before'
> > +
> > +    @has_many_index ||= $(@).siblings('fieldset').length
> > +    regex             = new RegExp $(@).data('placeholder'), 'g'
> > +    $(@).before unescape_html $(@).data('html').replace regex, ++@has_many_index
>
>  I'm not sure if this is the correct, I think you will end up w.
> duplicate indices if a fieldset is removed.
>
> If a fieldset is removed, the number will just keep counting up. So you
> might have some numbers not used at all, but at least they won't conflict.
>
> Also I don't quite understand what you mean about storing the index and
> how it helps with multiple has_many forms
>
> If I had a global variable that stored the current index, that wouldn't
> act sanely if you have mutliple has_many forms. Whereas this solution binds
> the index onto the add button, so it's unique to every has_many form.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/gregbell/active_admin/pull/2645/files#r7391569>
> .
>