From be1b458634fdb45ed58f6d7833facddc244fa2e7 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 14 May 2019 23:04:49 +1000 Subject: [PATCH] Upon successful creation (in a secondary modal) update the field in the primary modal --- InvenTree/static/script/inventree/modals.js | 16 +++++++++++++++- InvenTree/stock/forms.py | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/InvenTree/static/script/inventree/modals.js b/InvenTree/static/script/inventree/modals.js index 05a0473b42..4f9cb70068 100644 --- a/InvenTree/static/script/inventree/modals.js +++ b/InvenTree/static/script/inventree/modals.js @@ -102,7 +102,7 @@ function afterForm(response, options) { // Was a callback provided? if (options.success) { - options.success(); + options.success(response); } else if (options.follow && response.url) { window.location.href = response.url; @@ -400,6 +400,20 @@ function attachSecondaryModal(modal, options) { options.url, { modal: '#modal-form-secondary', + success: function(response) { + + /* A successful object creation event should return a response which contains: + * - pk: ID of the newly created object + * - text: String descriptor of the newly created object + * + * So it is simply a matter of appending and selecting the new object! + */ + + var select = '#id_' + options.field; + var option = new Option(response.text, response.pk, true, true) + + $(modal).find(select).append(option).trigger('change'); + } } ); }); diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index f181a6db88..ee8592bbb9 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -32,8 +32,8 @@ class CreateStockItemForm(HelperForm): 'part', 'supplier_part', 'location', - 'batch', 'quantity', + 'batch', 'delete_on_deplete', 'status', 'notes',