Fixed update bug in CorpContact admin selects

The problem is that Django RelatedObjectLookups.js is triggering select
changes for the initial value and we don't want to change the contact list
for this initial change (unless we lose the currently selected value).
This commit is contained in:
Claude Paroz 2019-11-20 14:53:24 +01:00
parent f39724f551
commit 579236986e
3 changed files with 6 additions and 4 deletions

View file

@ -2,11 +2,13 @@ django.jQuery(document).ready(function() {
django.jQuery('#id_corporation, .field-corporation select').change(function(ev) {
// Fill contact select
// Either in availability admin, or in stages admin with availability inlines
if (this.id == 'id_period') return;
if (this.id == 'id_corporation') var sel = django.jQuery('#id_contact');
else var sel = django.jQuery(this).closest('fieldset').find('.field-contact select');
sel.html('<option value="">-------</option>');
var id_corp = django.jQuery("option:selected", this).val();
django.jQuery.getJSON('/corporation/' + id_corp + '/contacts/', function(data) {
if (data.length && data[0].corporation_id == id_corp) return
sel.html('<option value="">-------</option>');
django.jQuery.each(data, function(key, contact) {
var item = contact.first_name + ' ' + contact.last_name;
if (contact.role.length) item += ' (' + contact.role + ')';