Hi,
Below is a Javascript file with the hackery we use to trigger a change
event when the add/change popup window is dismissed, which works for Django
1.7 at least.
Hopefully it will help, or at least point you in the right direction.
Regards,
James
/*
* Trigger change events when Django admin's popup window is dismissed
*/
(function($) {
$(document).ready(function() {
// HACK to override `dismissRelatedLookupPopup()` and
// `dismissAddAnotherPopup()` in Django's RelatedObjectLookups.js to
// trigger change event when an ID is selected or added via popup.
function triggerChangeOnField(win, chosenId) {
var name = windowname_to_id(win.name);
var elem = document.getElementById(name);
$(elem).change();
}
window.ORIGINAL_dismissRelatedLookupPopup =
window.dismissRelatedLookupPopup
window.dismissRelatedLookupPopup = function(win, chosenId) {
ORIGINAL_dismissRelatedLookupPopup(win, chosenId);
triggerChangeOnField(win, chosenId);
}
window.ORIGINAL_dismissAddAnotherPopup =
window.dismissAddAnotherPopup
window.dismissAddAnotherPopup = function(win, chosenId) {
ORIGINAL_dismissAddAnotherPopup(win, chosenId);
triggerChangeOnField(win, chosenId);
}
});
})(jQuery);
On Wednesday, 25 November 2015 21:39:06 UTC+11, [email protected] wrote:
>
> Hi,
>
> I see this question is not receiving a lot of love. Perhaps we can try
> to approach it differently then:
> What is the mechanism that populates back the parentform select once the
> pop-up form is completed and saved ? (As I have very limited experience
> with front-end web technologies, I would not know where to look for the
> code implementing that functionnality).
>
> From here, perhaps we can try to hook some custom Javascript.
>
> Thank you for reading,
> Ad
>
> Le vendredi 20 novembre 2015 09:55:10 UTC+1, [email protected] a écrit :
>>
>> Hi,
>>
>> We are developing an application that relies on dynamic admin pages
>> (based on some custom ajax). The high level idea is that, when the user
>> changes the value in a select html element that is mapped to a ForeignKey
>> on another model, we call a JS function (which triggers an asynchronous
>> request that changes the current admin form on completion).
>>
>>
>> To achieve that, we listen to the change event of said select (to call
>> the JS function when it is fired), which works fine when the user clicks
>> a value directly in the drop-down menu proposed by the select.
>>
>> Sadly, when this select is populated through the Admin Popup
>> functionality (the process that starts by clicking the green plus icon to
>> open a popup window, and that completes when the user click the save button
>> on the popup window), it seems that the change event is not fired for
>> the select, as our callback is not executed, even though the selected value
>> is actually changed.
>>
>> Is there another event we can listen to to get the same behaviour than
>> when the user clicks a value directly from the list ? Or any other method
>> to call our JS function when the select value is set through the popup
>> completion ?
>>
>> Thank you for reading,
>> Ad
>>
>> (Full disclosure: I first tried my luck with a question on SO
>> <http://stackoverflow.com/q/33789528/1027706>, without great success)
>>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/68fe1b94-ac57-4726-9fd8-a18cf610d74d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.