mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
[CUI] Non field errors (#7672)
* Fix typo * [CUI] Display hidden error messages in forms * Adjust build checks * Improve error checking
This commit is contained in:
parent
eacd28bf19
commit
234b0ed72c
@ -120,26 +120,28 @@ class Build(
|
|||||||
self.validate_reference_field(self.reference)
|
self.validate_reference_field(self.reference)
|
||||||
self.reference_int = self.rebuild_reference_field(self.reference)
|
self.reference_int = self.rebuild_reference_field(self.reference)
|
||||||
|
|
||||||
if get_global_setting('BUILDORDER_REQUIRE_VALID_BOM'):
|
# Check part when initially creating the build order
|
||||||
# Check that the BOM is valid
|
if not self.pk or self.has_field_changed('part'):
|
||||||
if not self.part.is_bom_valid():
|
if get_global_setting('BUILDORDER_REQUIRE_VALID_BOM'):
|
||||||
raise ValidationError({
|
# Check that the BOM is valid
|
||||||
'part': _('Assembly BOM has not been validated')
|
if not self.part.is_bom_valid():
|
||||||
})
|
raise ValidationError({
|
||||||
|
'part': _('Assembly BOM has not been validated')
|
||||||
|
})
|
||||||
|
|
||||||
if get_global_setting('BUILDORDER_REQUIRE_ACTIVE_PART'):
|
if get_global_setting('BUILDORDER_REQUIRE_ACTIVE_PART'):
|
||||||
# Check that the part is active
|
# Check that the part is active
|
||||||
if not self.part.active:
|
if not self.part.active:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'part': _('Build order cannot be created for an inactive part')
|
'part': _('Build order cannot be created for an inactive part')
|
||||||
})
|
})
|
||||||
|
|
||||||
if get_global_setting('BUILDORDER_REQUIRE_LOCKED_PART'):
|
if get_global_setting('BUILDORDER_REQUIRE_LOCKED_PART'):
|
||||||
# Check that the part is locked
|
# Check that the part is locked
|
||||||
if not self.part.locked:
|
if not self.part.locked:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'part': _('Build order cannot be created for an unlocked part')
|
'part': _('Build order cannot be created for an unlocked part')
|
||||||
})
|
})
|
||||||
|
|
||||||
# On first save (i.e. creation), run some extra checks
|
# On first save (i.e. creation), run some extra checks
|
||||||
if self.pk is None:
|
if self.pk is None:
|
||||||
|
@ -1502,8 +1502,23 @@ function handleFormErrors(errors, fields={}, options={}) {
|
|||||||
|
|
||||||
for (var field_name in errors) {
|
for (var field_name in errors) {
|
||||||
|
|
||||||
var field = fields[field_name] || {};
|
let field = fields[field_name] || null;
|
||||||
var field_errors = errors[field_name];
|
let field_errors = errors[field_name];
|
||||||
|
|
||||||
|
// No matching field - append to non_field_errors
|
||||||
|
if (!field || field.hidden) {
|
||||||
|
|
||||||
|
if (Array.isArray(field_errors)) {
|
||||||
|
field_errors.forEach((err) => {
|
||||||
|
non_field_errors.append(`<div class='alert alert-block alert-danger'>${err}</div>`);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
non_field_errors.append(`<div class='alert alert-block alert-danger'>${field_errors.toString()}</div>`);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// for nested objects with children and dependent fields with a child defined, extract nested errors
|
// for nested objects with children and dependent fields with a child defined, extract nested errors
|
||||||
if (((field.type == 'nested object') && ('children' in field)) || ((field.type == 'dependent field') && ('child' in field))) {
|
if (((field.type == 'nested object') && ('children' in field)) || ((field.type == 'dependent field') && ('child' in field))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user