Again, my apologies for the terrible formatting from my phone's email client



Here's an example from jquery docs:


http://api.jquery.com/trigger/


1

2

3

4

5


var event = jQuery.Event( "submit" );

$( "form:first" ).trigger( event );

if ( event.isDefaultPrevented() ) {

  // Perform an action...

}

On Sun, Nov 3, 2013 at 7:20 PM, Sean Linsley <notifications@github.com>
wrote:

>> +  #     fieldset.do_jquery_stuff_before_removal()
>> +  #
>> +  $(document).on 'click', 'a.button.has_many_remove', (e)->
>> +    e.preventDefault()
>> +    parent    = $(@).closest '.has_many'
>> +    to_remove = parent.children 'fieldset:last'
>> +
>> +    parent.trigger 'has_many_remove:before', [ to_remove ]
>> +    to_remove.remove()
>> +
>> +  # Provides before and after creation hooks:
>> +  # $ ->
>> +  #   # What would you do here?
>> +  #   $(document).on 'has_many_add:before', '.has_many', (e)->
>> +  #     # ...?
>> +  #
> That callback doesn't actually pass the fieldset down, because it hasn't been built yet. So:
> ```coffee
> $ ->
>   $(document).on 'has_many_add:before', '.has_many', (e)->
>     if $(@).children('fieldset').length > 9
>       alert "you reached the maximum number of items"
>       return false
> ```
> Unfortunately, that doesn't actually prevent the new fieldset from being added. So now the question I've been avoiding: how do we conditionally add the fieldset based on what the hook returns?
> If there isn't a good way to do that, I think I should remove the before-add hook because having it implies functionality that we don't provide.
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/gregbell/active_admin/pull/2645/files#r7392833