Trigger an event on add another

145 views
Skip to first unread message

James Pic

unread,
Nov 9, 2012, 6:29:26 AM11/9/12
to django-d...@googlegroups.com
Hi all,

Is it possible to trigger an event on add-another ?


Thanks for answering

Regards

Mark Lavin

unread,
Nov 9, 2012, 8:37:09 AM11/9/12
to django-d...@googlegroups.com
When I was working on a similar issue for django-selectable I created an issue to address this problem with a simple proof of concept patch https://code.djangoproject.com/ticket/15760. However I never followed through with the ticket to try to get something like this added. In the meantime another ticket was created and fixed which solves a large portion of the problem https://code.djangoproject.com/ticket/18241. With this change you can catch the click event of the add button. I still feel like the admin inline javascript is not particularly flexible and having some clearly documented hooks for this use case would be nice.

For what it's worth my solution in django-selectable was to patch the formset function to include my callback https://bitbucket.org/mlavin/django-selectable/src/efede3aa83ec6d372626eaac6f54c188287ec3d2/selectable/static/selectable/js/jquery.dj.selectable.js?at=default#cl-289 Not the prettiest solution but it works.

Best,

Mark

James Pic

unread,
Nov 23, 2012, 10:33:34 AM11/23/12
to django-d...@googlegroups.com
All Django admin would have to do is call: $(this).trigger('django.admin.another_added') or something like that.

It really sounds like little work and would allow user defined callbacks to be executed.

What do you think ?
--
http://blog.yourlabs.org
Customer is king - Le client est roi - El cliente es rey.

is_null

unread,
Nov 23, 2012, 10:39:23 AM11/23/12
to django-d...@googlegroups.com
My bad I didn't see Mark's mail, I'll subscribe to the list and hopefully this shouldn't happen again.

Thanks Mark for answering

is_null

unread,
Nov 28, 2012, 8:44:03 AM11/28/12
to django-d...@googlegroups.com
FTR, another solution is to intercept creation of <option> tags with DOMNodeInserted. Requires no monkey patch and is compatible with django & django-grappelli out of the box: https://github.com/yourlabs/django-autocomplete-light/commit/1f1e715e20

Thanks again for your answer (which I credited in the related github issue).

Rock'on
Reply all
Reply to author
Forward
0 new messages