Upon successful creation (in a secondary modal) update the field in the primary modal

This commit is contained in:
Oliver Walters 2019-05-14 23:04:49 +10:00
parent a316681ec8
commit be1b458634
2 changed files with 16 additions and 2 deletions

View File

@ -102,7 +102,7 @@ function afterForm(response, options) {
// Was a callback provided? // Was a callback provided?
if (options.success) { if (options.success) {
options.success(); options.success(response);
} }
else if (options.follow && response.url) { else if (options.follow && response.url) {
window.location.href = response.url; window.location.href = response.url;
@ -400,6 +400,20 @@ function attachSecondaryModal(modal, options) {
options.url, options.url,
{ {
modal: '#modal-form-secondary', 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');
}
} }
); );
}); });

View File

@ -32,8 +32,8 @@ class CreateStockItemForm(HelperForm):
'part', 'part',
'supplier_part', 'supplier_part',
'location', 'location',
'batch',
'quantity', 'quantity',
'batch',
'delete_on_deplete', 'delete_on_deplete',
'status', 'status',
'notes', 'notes',