IntelliJ Platform Plugin SDK Help

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

Or inline, above the confirmation buttons:

Example inline

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:

Port correct

If it’s not obvious that only numbers can be entered, allow entering any sign and perform validation.

Font error

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

Non-allowed characters or too big/long values

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

Empty required fields in dialogs

Disable the confirmation button or check on sending the form

Tooltip

4

Non-allowed or empty values in the main window

On Enter or focus loss

Tooltip

5

Remote connection

On sending the form

Tooltip or inline

6

Complex values in multi-page dialogs

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

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

Hide the error when the incorrect symbol is deleted.

Implementation

val MESSAGE = "The port number must be between 0 and 65535"; textField() .validationOnInput { val portString = it.text if (portString.isNotEmpty()) { try { val portValue = portString.toInt() if (portValue < 0 || portValue > 65535) { error(MESSAGE) } else { null } } catch (_: NumberFormatException) { error(MESSAGE) } } else { null } }
// Fields initializers private JTextField myPort = new JTextField(); private static final String MESSAGE = "The port number must be between 0 and 65535"; // Components initialization new ComponentValidator(parentDisposable).withValidator(() -> { String pt = myPort.getText(); if (StringUtil.isNotEmpty(pt)) { try { int portValue = Integer.parseInt(pt); if (portValue >= 0 && portValue <= 65535) { return null; } else { return new ValidationInfo(MESSAGE, myPort); } } catch (NumberFormatException nfe) { return new ValidationInfo(MESSAGE, myPort); } } else { return null; } }).installOn(myPort); myPort.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(@NotNull DocumentEvent e) { ComponentValidator.getInstance(myPort) .ifPresent(v -> v.revalidate()); } });

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

If validated on focus loss, highlight the field in light-red. Do not return focus to the field with the error automatically.

Focus loss

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

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:

textField() .validationOnApply { ... }

Add andStartOnFocusLost() call on ComponentValidator before installing it on a component:

new ComponentValidator(parentDisposable) .withValidator(...) .andStartOnFocusLost() .installOn(textField);

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

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

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:

error("The host cannot be reached") .withOkEnabled()
new ValidationInfo("The host cannot be reached", myHostField) .withOkEnabled();

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

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

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:

new ValidationInfo( "The host cannot be reached. Check the address and credentials.");

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

show the following dialog on pressing the confirmation button:

Confirmation dialog

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

If the field loses focus, hide the tooltip and highlight the field with light-red:

Incorrect symbol non focused

On hover over the field or the element with an error:

Incorrect symbol hover
Validation table hover

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
It’s clear how to fix the error from the error description.

Message long
The way to solve the problem is provided.

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

Message unclear

Correct

Message clear

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

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

The warning can be shown:

In a tooltip for a specific field. Follow the rules for the error tooltip.

warning("Target name is not specified")
new ValidationInfo("Target name is not specified", myNameField) .asWarning();

On the form under the controls. Show the message with the yellow warning icon.

Warning inline

On the "Problems" page in complex multipage dialogs. Show warnings and fix options:

Problems
Problems page in the Project Structure dialog.

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

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

Combo box

Combo box

Tables and lists

Table error

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

Use a warning icon for warnings:

Table warning

Implementation

val cellEditor = JTextField() cellEditor.putClientProperty(DarculaUIUtil.COMPACT_PROPERTY, true) cellEditor.document.addDocumentListener(object : DocumentAdapter() { override fun textChanged(e: DocumentEvent) { val outline = if (cellEditor.text.contains(".")) "error" else null cellEditor.putClientProperty("JComponent.outline", outline) } }) val firstColumn = table.columnModel.getColumn(0) firstColumn.cellEditor = DefaultCellEditor(cellEditor) firstColumn.cellRenderer = object : DefaultTableCellRenderer() { override fun getPreferredSize(): Dimension { val size = super.preferredSize val editorSize = cellEditor.preferredSize size.height = max(size.height, editorSize.height) return size } }
JTextField cellEditor = new JTextField(); cellEditor.putClientProperty( DarculaUIUtil.COMPACT_PROPERTY, Boolean.TRUE); cellEditor.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(@NotNull DocumentEvent e) { Object outline = cellEditor.getText().contains(".") ? "error" : null; cellEditor.putClientProperty("JComponent.outline", outline); } }); TableColumn firstColumn = table.getColumnModel().getColumn(0); firstColumn.setCellEditor(new DefaultCellEditor(cellEditor)); firstColumn.setCellRenderer(new DefaultTableCellRenderer() { @Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); Dimension editorSize = cellEditor.getPreferredSize(); size.height = Math.max(size.height, editorSize.height); return size; } });

Trees and lists

Add an error or warning icon on the right side of the invalid line.

List

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

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

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

Do not show an error message inside the empty required field. It looks like a prefilled field, not like an error message.

Goto line

Do not underline the field label. It looks like a spell error and poorly visible.

Underline

Do not shake a form and show an error with a delay. A shaking form is distracting and time-consuming.

New class

Do not show an error immediately after opening a form. It distracts the user from filling the form.

Add tfs

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

Insets and colors

Tooltip insets
Dialog insets
Last modified: 06 August 2024