Triggering 'chosen:updated' on Django Admin popup close

55
December 23, 2018, at 11:10 PM

I'm using the Django Admin portal as my primary methodology for toying with models in the database for my application and I prefer using the Chosen Select plugin to represent the select elements on the page. By default, the Django Admin pages are configured to trigger select elements to update their options if you modify them via the change-related, add-related, or delete-related buttons next to the appropriate fields. However, this doesn't seem to trigger the change event for the select element...

I have the following code in a custom JavaScript file tied to the admin pages:

$(document).ready(function() {
    options = {
        no_results_text: "Entity not found...",
        placeholder_text_multiple: "Choose entities...",
        search_contains: true
    }
    $('select').chosen(options).change(function () {
        $(this).trigger('chosen:updated');
    });
});

I know that this code does its job because the use of $('#select').change() in the browser's console will update the Chosen Select element accordingly, but this event isn't fired when the Admin popup window is closed and the select element's value is changed...

In short, I need to know what what event is triggered when the select element's options are changed so I can update the Chosen Select box as well. I could in theory have an event fire when the button that's clicked to open the popup window gets focus again (after the popup is closed), but that seems clunky and I'd prefer not to do that...

READ ALSO
How to add manifest.json to html with parcel.js bundler?

How to add manifest.json to html with parcel.js bundler?

I am using Parceljs to bundle my files

21
TypeORM, update query in one to many relationship

TypeORM, update query in one to many relationship

How can I update an one to many relationship? I have this two tables:

58
Django-taggit query objects if the tag field contains 2 or more elements?

Django-taggit query objects if the tag field contains 2 or more elements?

I'm wondering how to query multiple tags through taggitI'm currently using django-taggit

68