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

Refactor PriceBreakCreate form

- Handle non_field_errors
This commit is contained in:
Oliver
2021-06-30 14:07:15 +10:00
parent 8f47035a7b
commit 09fff5b644
5 changed files with 55 additions and 67 deletions

View File

@ -302,6 +302,8 @@ function constructFormBody(fields, options) {
var html = '';
html += `<div id='non-field-errors'><!-- Empty div for displaying errors --></div>`;
// Client must provide set of fields to be displayed,
// otherwise *all* fields will be displayed
var displayed_fields = options.fields || fields;
@ -653,6 +655,9 @@ function clearFormErrors(options) {
// Remove the "has error" class
$(options.modal).find('.has-error').removeClass('has-error');
// Clear the 'non field errors'
$(options.modal).find('#non-field-errors').html('');
}
@ -669,6 +674,31 @@ function handleFormErrors(errors, fields, options) {
// Remove any existing error messages from the form
clearFormErrors(options);
var non_field_errors = $(options.modal).find('#non-field-errors');
non_field_errors.append(
`<div class='alert alert-block alert-danger'>
<b>{% trans "Form errors exist" %}</b>
</div>`
);
// Non-field errors?
if ('non_field_errors' in errors) {
var nfe = errors.non_field_errors;
for (var idx = 0; idx < nfe.length; idx++) {
var err = nfe[idx];
var html = `
<div class='alert alert-block alert-danger'>
${err}
</div>`;
non_field_errors.append(html);
}
}
for (field_name in errors) {
if (field_name in fields) {