netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Highlight field labels in forms when CUSTOM_VALIDATORS defined with field required:True

Open simonzsay opened this issue 4 weeks ago • 1 comments

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},
    }
]
Image

Will be great to see it bold and with star *, like this

Image

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.

Image

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.

simonzsay avatar Dec 03 '25 08:12 simonzsay

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.

jeremystretch avatar Dec 04 '25 17:12 jeremystretch