Highlight field labels in forms when CUSTOM_VALIDATORS defined with field required:True
NetBox version
v4.4.6
Feature type
New functionality
Proposed functionality
I’m trying to make several fields required in NetBox forms, even though they are not mandatory by default. According to the documentation, this should be possible using CUSTOM_VALIDATORS. I tested the following configuration on a development server (extra.py):
CUSTOM_VALIDATORS = {
"dcim.site": [
{
"region": {"required": True},
"tenant": {"required": True},
"time_zone": {"required": True},
"physical_address": {"required": True},
"shipping_address": {"required": True},
"facility": {"required": True},
},
],
"dcim.location": [
{
"tenant": {"required": True},
},
],
"dcim.rack": [
{
"location": {"required": True},
"role": {"required": True},
"tenant": {"required": True},
},
],
"dcim.rackreservation": [
{
"tenant": {"required": True},
},
],
"dcim.device": [
{
"name": {"required": True},
"tenant": {"required": True},
"location": {"required": True},
"rack": {"required": True},
},
],
}
Functionally everything works — validation correctly prevents saving objects when these fields are empty.
However, the UI does not indicate that these fields are required. For example, with the following configuration:
"dcim.device": [
{
"tenant": {"required": True},
}
]
Will be great to see it bold and with star *, like this
When user skips some field in the form he can see notification in UI, but for only first validated field. He fills this field, click "save" and again get new validation error with next field.
Use case
Current way quite confusing for users because the field appears optional, but the form fails to submit unless it is filled in. With offered way where all "custom required fields" have bold text and star *, form will be filled from first attempt instead of 2-3 or even more.
Database changes
Sorry, i can`t provide details about data base.
External dependencies
Sorry, i can`t provide details about dependencies.
While I like the idea in principle, this might prove tricky to implement because there's no direct correlation from individual forms to custom validators. We could try to stitch them together, but care will be needed to avoid enforcing custom validators for any object attributes are not being modified by the form.