Validation Errors
Validation is the process of checking the values specified by the user, and displaying the errors that are found.
An error can appear in a tooltip:
![Example tooltip Example tooltip](images/example_tooltip.png)
Or inline, above the confirmation buttons:
![Example inline Example inline](images/example_inline.png)
Principles
Always try not to let the user enter invalid data. To achieve this:
Use controls that are constrained to valid values. For example, use a combo box or a slider instead of the input field.
Limit the characters users can enter. For example, if only numbers are supported in a field, and this is obvious to the user, ignore input of letters instead of showing an error:
If it’s not obvious that only numbers can be entered, allow entering any sign and perform validation.
![Font error Font error](images/font_error.png)
Provide a default value if possible. Even if the user decides to change the default value, it gives a clue on the expected input format.
Write instructions and examples on how to fill a form using context help.
If it’s not possible to limit input, try to show an error as soon as possible so that the user can quickly return and fix it.
Validation types and usage
What to validate | Validation type | Format | |
---|---|---|---|
1 | Immediately on input | Tooltip | |
2 | Non-allowed values in dialogs. For example, an existing file name, a value that does not match the pattern, or a value that’s too small | On sending the form or on focus loss | Tooltip |
3 | Disable the confirmation button or check on sending the form | Tooltip | |
4 | On Enter or focus loss | Tooltip | |
5 | On sending the form | Tooltip or inline | |
6 | On reopening the form or when the values are used | Tooltip, inline or notification |
1. Non-allowed characters or too big values
If a non-allowed character is entered, or the maximum input size or value is exceeded, validate it immediately on input.
How it works
The field is highlighted with red, and the error appears in the tooltip.
![Create class Create class](images/create_class.png)
If the maximum value is exceeded, specify what values are allowed (e.g. a range for numeric values, or the number of symbols):
![Port error Port error](images/port_error.png)
Hide the error when the incorrect symbol is deleted.
Implementation
See also: Choosing a Disposable Parent.
2. Non-allowed values in dialogs
A non-allowed value is a value that can be checked only when fully entered. For example, an existing file name, value that does not match the pattern or a value that’s too small/short.
If a non-allowed value is entered, validate it on focus loss or on sending the form, depending on what happens faster.
Do not validate non-allowed values on input, it will interrupt the user.
Do not validate empty fields on focus loss. Users should be able to fill the form in a random order, so do not interrupt them.
How it works
On sending the form, the field is highlighted in red and the error tooltip appears.
![Exesting name Exesting name](images/exesting_name.png)
If validated on focus loss, highlight the field in light-red. Do not return focus to the field with the error automatically.
![Focus loss Focus loss](images/focus_loss.png)
The error tooltip appears when the invalid field gets the focus or on hovering over the field.
When the user changes the value, the tooltip disappears and error highlighting is replaced with the regular focus:
![Fix error Fix error](images/fix_error.png)
When the focus is returned to the field with an error, use validation on input. Otherwise, it can be unclear for the user how to initiate validation.
Implementation
In Configurable
panels, throw ConfigurationException
from apply()
in case of errors.
Non-configurable panels:
Add andStartOnFocusLost()
call on ComponentValidator
before installing it on a component:
3. Empty required fields in dialogs
Simple form
If a form is simple, move the focus to the first required field and disable the confirmation button until all required fields have been filled. It is clear from the form behavior that input is required, showing validation messages is redundant.
![Simple dialog Simple dialog](images/simple_dialog.png)
Complex form
If a form is complex, always enable the confirmation button. Otherwise, it can be hard to understand what should be done to complete the form.
Complex forms are:
Forms with more than 3 input fields or combo boxes.
Forms with at least one control (checkbox, table, and so on) apart from an input field and a combo box.
Never validate empty required fields on input or focus loss. Users should be able to fill the form in a random order, so do not interrupt them.
How to use
Validation is performed when the user clicks the confirmation button (for example, the "Add" button).
Highlight all invalid fields, move the focus to the first invalid field and show the tooltip.
![Complex dialog Complex dialog](images/complex_dialog.png)
Hide the tooltip and the red highlighting when the user starts editing the invalid value or entering symbols into the empty required field.
Show the error tooltip for the next field when it gets the focus, hover, or the user clicks the "Add" button one more time.
Implementation
By default, DialogWrapper
disables OK button until all fields that participate in validation become valid.
Explicitly enable OK button for each input field:
4. Non-allowed or empty values in the main window
If a non-allowed or an empty value is entered into a field that’s within the Properties view, for example, in UI Designers like the Android Studio Layout Editor, validate it on pressing Enter or focus loss.
How it works
On Enter, the field is highlighted with red and the error tooltip appears.
![Main window Main window](images/main_window.png)
If validated on focus loss, the field is highlighted with light-red. The focus is not returned to the field automatically.
Hide the field highlighting and the tooltip when the user fixes the invalid value.
5. Remote connection
If validation is slow or attempts are limited, for example, due to connection to a remote server, validate values on sending the form.
If it’s not possible to detect the fields with errors, show the error message inline under the fields:
![Example inline Example inline](images/example_inline.png)
An inline error only appears on clicking the confirmation button. The dialog is resized to fit the error message. Do not leave an empty space for the error in advance.
Hide the error messages once any field related to the error is edited. Set the dialog to its original size when the error disappears.
Implementation
ValidationInfo
for messages in inline area is created with null
component:
6. Complex values in multi-page dialogs
If a value is complex, for example, a list of values, a regexp, or a value copied from another place, and it appears in a multi-page dialog, such as Settings, Project Structure or Run Configurations, show a dialog informing the user about an error on clicking the confirmation button.
For example, in a complex Resource patterns field
![Comlex field Comlex field](images/comlex_field.png)
show the following dialog on pressing the confirmation button:
![Confirmation dialog Confirmation dialog](images/confirmation_dialog.png)
It should be possible to close the Settings dialog and save the entered data if the user wants to fix the values later or needs additional data outside of the modal Settings dialog.
If an invalid field is not empty, highlight it on reopening the Settings dialog or report the error when the entered data is used.
Tooltip
An error tooltip appears in two cases:
If the field with an error gets focus:
![Example tooltip Example tooltip](images/example_tooltip.png)
If the field loses focus, hide the tooltip and highlight the field with light-red:
On hover over the field or the element with an error:
![Incorrect symbol hover Incorrect symbol hover](images/incorrect_symbol_hover.png)
![Validation table hover Validation table hover](images/validation_table_hover.png)
Show the tooltip above the field and move it 40px right, so that the controls above it are not overlapped. If there is important info above the field, the tooltip can be shown on the right.
Error message text
An error message describes the problem and provides the way to solve it if it’s not clear from the problem description.
![Message short Message short](images/message_short.png)
![Message long Message long](images/message_long.png)
Describe the problem in terms of target users’ actions or goals, not in terms of the program’s architecture.
Incorrect | Invalid Git Executable. Error running "git.exe". File not found: "git.exe". |
---|---|
Correct | Cannot run "git.exe". The file is not found. |
Provide specific names, locations, and values of the objects involved:
Incorrect | ![]() |
---|---|
Correct | ![]() |
For a period at the end of an error message, see Punctuation.
Make the error message short and descriptive. See Writing short and clear.
Examples of common errors and corresponding error messages:
Error type | Error message |
---|---|
Empty required field | Specify the port number |
Incorrect symbol | "/" is not an allowed symbol |
Incorrect value | The port number should be between XXX and XXXX The file name should be at least 4 symbols The name is already in use The username or password is incorrect |
Incorrect format | The email format should be xxx@xxx.com |
Missing file | The file is not found |
Use encouraging tone:
Do not use | Use |
---|---|
Error, failure | Problem |
Failed to | Unable |
Illegal, invalid, bad | Incorrect |
Must | Should be |
Warning
![Validation warning Validation warning](images/validation_warning.png)
A warning informs the user that something is configured incorrectly, but does not prevent them from applying the changes.
A warning can appear on input, focus loss, or on reopening a filled form. For example, make the empty field Target name show a warning on reopening:
![Warning dialog Warning dialog](images/warning_dialog.png)
The warning can be shown:
In a tooltip for a specific field. Follow the rules for the error tooltip.
On the form under the controls. Show the message with the yellow warning icon.
![Warning inline Warning inline](images/warning_inline.png)
On the "Problems" page in complex multipage dialogs. Show warnings and fix options:
![Problems Problems](images/problems.png)
Mark all navigation elements for areas that contain warnings with yellow icons.
Update the problem counter when a problem is detected. When all problems have been fixed, do not show the "Problems" tab.
On a particular page, highlight the element that contains a warning in yellow or add a warning icon next to it.
UI elements with validation errors
Input field
![Example tooltip Example tooltip](images/example_tooltip.png)
Add a red light bulb on the right side of the input field if an action to fix the error is available:
![Input field bulb Input field bulb](images/input_field_bulb.png)
Combo box
![Combo box Combo box](images/combo_box.png)
Tables and lists
![Table error Table error](images/table_error.png)
When the field in a table loses focus, show an error icon. An error tooltip appears on mouse hover or when the line gets focus:
![Validation table hover Validation table hover](images/validation_table_hover.png)
Use a warning icon for warnings:
![Table warning Table warning](images/table_warning.png)
Implementation
Trees and lists
Add an error or warning icon on the right side of the invalid line.
![List List](images/list.png)
Multi-page dialog
If validation in a multipage form can be performed only by clicking the confirmation button, then:
Use red highlighting for navigation elements such as tabs, menu and list items for areas that contain errors so that the user can quickly locate the error.
Open the first page with an error or stay on the opened page if it has errors on clicking the confirmation button.
![Multipage1 Multipage1](images/multipage1.png)
Avoid mistakes
Do not show an error in a message box. Users are pulled out of the context, they need to close the dialog and locate the invalid field.
![Message box Message box](images/message_box.png)
Do not allow to click "OK" button if a form contains empty required fields. For this, the Cancel button should be used, and the OK button should be disabled. Otherwise, if users accidentally leave the field empty, they can expect that the value was entered correctly.
![Wildcard Wildcard](images/wildcard.png)
Do not show an error message inside the empty required field. It looks like a prefilled field, not like an error message.
![Goto line Goto line](images/goto_line.png)
Do not underline the field label. It looks like a spell error and poorly visible.
![Underline Underline](images/underline.png)
Do not shake a form and show an error with a delay. A shaking form is distracting and time-consuming.
![New class New class](images/new_class.png)
Do not show an error immediately after opening a form. It distracts the user from filling the form.
![Add tfs Add tfs](images/add_tfs.png)
Do not allow submitting the form with the error. When the form is opened again, the value is reset, so users don’t know if they entered incorrect data.
![Save Save](images/save.png)
Insets and colors
![Tooltip insets Tooltip insets](images/tooltip_insets.png)
![Dialog insets Dialog insets](images/dialog_insets.png)