-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display of client- vs. server-side form errors is inconsistent #8058
Comments
This is a minor UI issue |
Please specify exactly what you're doing so that someone else might attempt to replicate the behavior. |
Test setup 1
2a. Add device with missing default required field, eg site, and save. 2a result is similar to this 2b result is similar to this 3 result is similar to this Note the actual validators I'm using from the screen shots is different to the test case shown, I did get the same results with this validator though, while the text of the error differs the UI layout from them is the same. The validator used for the screen shots is a Custom Validator python script which is substantially more complex, both the config validator python script and config based customer validator behave the same. |
Test setup 2 For UI purposes the results using this customer validator class are exactly the same for device and virtual machine. Site and tenant which wasn't tested using the config based validators behave the same as virtual machine.
|
So, the green boxes come from the form validation that happens on submit. There currently is no way to maintain them during submit when the custom validation happens. The error could be clarified. Instead of However, one option might be to instead inject some of the Custom validation into the form if there is a regex, required, min, max, min_length, max_length, required or prohibited set. This possibly falls down when you have more then 1 validator running for a specific model with the same fields set (regex, required, etc) or with a custom validation class. |
From reading this and looking at the behavior the custom validator run after form validation, ie they only trigger if the form doesn't have default problems so this make sense. With this bug if there is no easy way to add the green/red field boarders then I'd suggest aiming for all custom validation to behave as device customer validation errors do
Other Netbox objects I've tested (site, tenant and virtual machine) only have the pop up, the text area is absent. This is a very minor issue, is just stood out to me. |
I wonder if we could do a post using htmx now. That might allow us to retain the errors and validation. |
The red & green field borders are added on the client side: The missing field is highlighted because the browser knows that it's a required field but empty. The validation logic is applied on the server side, and when it fails, an entire new form is rendered with the appropriate messages. (Incidentally, I have an open item under #7449 to remove the green border from valid fields as it can be distracting.) I think the root issue here is that server-side form errors are not being displayed inline with the form fields as the client-side errors are. This isn't specifically related to custom validators; the same seems to be true for any server-side validation errors. We probably just need to tweak the form rendering templates to apply field-specific errors more consistently. |
I've modified how form field errors are rendered under f56e3eb for NetBox v3.4. Error messages are now embedded inline beneath each field rather than being displayed as "toasts" in the bottom right corner. I believe this satisfies at least the bulk of the concerns raised in this issue. I'm open to further discussion of ways to improve form rendering in general, however any further work in this area should be captured as separate feature requests. |
NetBox version
v3.1.0
Python version
3.7
Steps to Reproduce
Expected Behavior
Observed Behavior
For Device
3. A pop up dialogue appears
4. At the top of the form a Errors section appear
5. Some fields have green ticks and a green border but they disappear
6. The field in error doesn't have a green tick but has a green border
For VM
3. A pop up dialogue appears
4. Some fields have green ticks and a green border but they disappear
5. The field in error doesn't have a green tick but has a green border
The text was updated successfully, but these errors were encountered: