Hi,
as you can see, I added the inline_autocomplete demo so I can add more issues for autocomplete inside inlines :-)
I am currently trying to write some code, that uses dependent autocomplete, only in inlines.
To reproduce the problem I am issuing here, first please run the demo and open inlines_autocomplete "add new":
http://localhost:8000/admin/inline_autocomplete/trip/add/
Then, in the browser: launch Firebug or anything you prefer, and then type in console:
>>> $('.autocomplete-light-widget.trip_city_set-0-city').yourlabsWidget()
Object { widget=[1], input=[1], select=[1], więcej...}
As you can see, this works. The widget is found.
Now, please add one more inline, by clicking "Add another Trip_City" link on the page.
Now, let's try to access newly created widget:
>>> $('.autocomplete-light-widget.trip_city_set-1-city').yourlabsWidget()
undefined
... but, when you check all the widgets:
>>> $('.autocomplete-light-widget')
You will see, that there is a with ID id_trip_city_set-1-city-wrapper
.
After some time, I found, that:
>>> $('.autocomplete-light-widget.trip_city_set-__prefix__-city')
... will show TWO widgets named like this. One - invisible widget - was copied by django's inlines.js into a new one, which is visible.
Do you have any idea, why the widget retains the original ID (with "prefix" string not updated to an integer)?
Django after copying the invisible row, updates the "prefix" string inside id attributes in inlines.js, line 20 (updateElementIndex).
I suppose I should do something after the widget is copied, like, call a function that will make jQuery to update widget's internal values from id attributes - or something like that. Please help me with this and I will think of creating a sensible patch for that.