Opened 14 years ago

Closed 13 years ago

Last modified 12 years ago

#16359 closed Cleanup/optimization (duplicate)

Listen to click events from "Add another" admin inline link should be easier

Reported by: contact@… Owned by: Michael Manfre
Component: contrib.admin Version: 1.3
Severity: Normal Keywords: admin, javascript, event, add another
Cc: dguardiola@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When creating custom fields for django admin inlines, it is handy to be able to listen to an even fired by clicking on "add another". I would like to listen to the click event to initiate my jquery plugin and pass it some parameters. Currently this is (to my knowledge) not possible. When binding the click event to it, it doesn't work:

    $('a').live('click', function() {
        console.log('add clicked');
    });

Also binding click to .add-row doesn't work. Apparently some other script (admin/js/inlines.min.js) which listens to the same element returns false.

To make this work inlines.min.js should not return false, or raise another event.
To make it more easy to work with, the link should get an id like #row-add-another.

Change History (4)

comment:1 by Simon Charette, 14 years ago

I agree that binding to those kind of events is a pain. The admin should definitly trigger namespaced events http://api.jquery.com/trigger/.

So far I've managed to workaround this issue by binding ".add-row a" click event and/or binding the DOMNodeInserted event which is not pretty:

$('#my_inline-group .dynamic-my_inline').live('DOMNodeInserted', console.log)

comment:2 by Michael Manfre, 14 years ago

Keywords: admin javascript event add another added
Owner: changed from nobody to Michael Manfre
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:3 by Julien Phalip, 13 years ago

Resolution: duplicate
Status: assignedclosed

This is a duplicate of #15760, which also has a patch.

comment:4 by domguard, 12 years ago

Cc: dguardiola@… added
Note: See TracTickets for help on using tickets.
Back to Top