2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-01 13:06:45 +00:00

Fix issues when re-opening a secondary modal

This commit is contained in:
Oliver Walters 2022-01-19 19:18:20 +11:00
parent 3c328feb65
commit 9ffcdbc417
2 changed files with 13 additions and 9 deletions

View File

@ -1380,23 +1380,23 @@ function initializeRelatedFields(fields, options) {
*/ */
function addSecondaryModal(field, fields, options) { function addSecondaryModal(field, fields, options) {
var name = field.name; var field_name = getFieldName(field.name, options);
var depth = options.depth || 0; var depth = options.depth || 0;
var secondary = field.secondary;
var html = ` var html = `
<span style='float: right;'> <span style='float: right;'>
<div type='button' class='btn btn-primary btn-secondary btn-form-secondary' title='${secondary.title || secondary.label}' id='btn-new-${name}'> <div type='button' class='btn btn-primary btn-secondary btn-form-secondary' title='${field.secondary.title || field.secondary.label}' id='btn-new-${field_name}'>
${secondary.label || secondary.title} ${field.secondary.label || field.secondary.title}
</div> </div>
</span>`; </span>`;
$(options.modal).find(`label[for="id_${name}"]`).append(html); $(options.modal).find(`label[for="id_${field_name}"]`).append(html);
// Callback function when the secondary button is pressed // Callback function when the secondary button is pressed
$(options.modal).find(`#btn-new-${name}`).click(function() { $(options.modal).find(`#btn-new-${field_name}`).click(function() {
var secondary = field.secondary;
// Determine the API query URL // Determine the API query URL
var url = secondary.api_url || field.api_url; var url = secondary.api_url || field.api_url;
@ -1417,8 +1417,7 @@ function addSecondaryModal(field, fields, options) {
// Force refresh from the API, to get full detail // Force refresh from the API, to get full detail
inventreeGet(`${url}${data.pk}/`, {}, { inventreeGet(`${url}${data.pk}/`, {}, {
success: function(responseData) { success: function(responseData) {
setRelatedFieldData(field.name, responseData, options);
setRelatedFieldData(name, responseData, options);
} }
}); });
}; };
@ -1432,6 +1431,8 @@ function addSecondaryModal(field, fields, options) {
// Method should be "POST" for creation // Method should be "POST" for creation
secondary.method = secondary.method || 'POST'; secondary.method = secondary.method || 'POST';
secondary.modal = null;
secondary.depth = depth + 1; secondary.depth = depth + 1;
constructForm( constructForm(

View File

@ -127,6 +127,9 @@ function createNewModal(options={}) {
$(modal_name).find('#modal-form-cancel').hide(); $(modal_name).find('#modal-form-cancel').hide();
} }
// Steal keyboard focus
$(modal_name).focus();
// Return the "name" of the modal // Return the "name" of the modal
return modal_name; return modal_name;
} }