Code

Opened 3 years ago

Closed 3 years ago

Last modified 17 months ago

#16359 closed Cleanup/optimization (duplicate)

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

Reported by: contact@… Owned by: 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.

Attachments (0)

Change History (4)

comment:1 Changed 3 years ago by charettes

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 3 years ago by manfre

  • Keywords admin, javascript, event, add another added
  • Owner changed from nobody to manfre
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by julien

  • Resolution set to duplicate
  • Status changed from assigned to closed

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

comment:4 Changed 17 months ago by quinode

  • Cc dguardiola@… added

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.