Merge pull request #1680 from matmair/modal-options

more modal options
This commit is contained in:
Oliver 2021-06-18 10:30:18 +10:00 committed by GitHub
commit b6e3df4e6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -776,7 +776,8 @@ function handleModalForm(url, options) {
// Form was returned, invalid! // Form was returned, invalid!
else { else {
if (!options.hideErrorMessage) { // Disable error message with option or response
if (!options.hideErrorMessage && !response.hideErrorMessage) {
var warningDiv = $(modal).find('#form-validation-warning'); var warningDiv = $(modal).find('#form-validation-warning');
warningDiv.css('display', 'block'); warningDiv.css('display', 'block');
} }
@ -791,6 +792,19 @@ function handleModalForm(url, options) {
if (options.secondary) { if (options.secondary) {
attachSecondaries(modal, options.secondary); attachSecondaries(modal, options.secondary);
} }
// Set modal title with response
if (response.title) {
modalSetTitle(modal, response.title);
}
// Clean custom action buttons
$(modal).find('#modal-footer-buttons').html('');
// Add custom action buttons with response
if (response.buttons) {
attachButtons(modal, response.buttons);
}
} }
else { else {
$(modal).modal('hide'); $(modal).modal('hide');
@ -837,6 +851,7 @@ function launchModalForm(url, options = {}) {
* secondary - List of secondary modals to attach * secondary - List of secondary modals to attach
* callback - List of callback functions to attach to inputs * callback - List of callback functions to attach to inputs
* focus - Select which field to focus on by default * focus - Select which field to focus on by default
* buttons - additional buttons that should be added as array with [name, title]
*/ */
var modal = options.modal || '#modal-form'; var modal = options.modal || '#modal-form';
@ -896,6 +911,11 @@ function launchModalForm(url, options = {}) {
attachButtons(modal, options.buttons); attachButtons(modal, options.buttons);
} }
// Add custom buttons from response
if (response.buttons) {
attachButtons(modal, response.buttons);
}
} else { } else {
$(modal).modal('hide'); $(modal).modal('hide');
showAlertDialog('{% trans "Invalid server response" %}', '{% trans "JSON response missing form data" %}'); showAlertDialog('{% trans "Invalid server response" %}', '{% trans "JSON response missing form data" %}');