You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`ValidationEvent` is fired in views inherited from `StandardDetailView` when the view is validated on saving the view xref:data/data-context.adoc[DataContext]. Use this event listener to perform additional validation of the view.
134
+
`ValidationEvent` is fired in views inherited from `StandardDetailView` when the view is saved. You can use this event listener to perform custom validation of the view.
135
+
136
+
To report validation errors and abort the save process, use the `ValidationErrors` object returned by the `getErrors()` method of the event. For example:
If the `ValidationErrors` object is not empty after the validation process, the saving operation will not be executed, and the view will display errors using the `ViewValidation.showValidationErrors()` method.
144
+
145
+
See xref:views/view-validation.adoc[] for more information.
Copy file name to clipboardExpand all lines: content/modules/flow-ui/pages/views/view-validation.adoc
+20-6Lines changed: 20 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,24 +1,38 @@
1
1
= View Validation
2
2
:page-aliases: screens/validation.adoc
3
3
4
-
Data validation in UI views is performed by the `ViewValidation` bean. It contains methods for validating UI components, displaying validation errors and unsaved changes dialogs. It is used by views and dialogs of the framework and add-ons. You can use it in the application views as well.
4
+
[[validation-steps]]
5
+
== Validation Steps
6
+
7
+
Before the detail view saves data during the execution of `closeWithSave()` and `save()` xref:views/view-methods.adoc#methods-of-standard-detail[methods], it validates the data in the following order:
8
+
9
+
. The view invokes the `validateUiComponents()` method of the `ViewValidation` bean described <<validateUiComponents,below>>.
10
+
11
+
. If there were no errors on the first step, the view sends the xref:views/view-events.adoc#validation-event[ValidationEvent] event, that can be handled in the view controller for additional validation.
12
+
13
+
[[view-validation-bean]]
14
+
== ViewValidation Bean
15
+
16
+
The `ViewValidation` bean contains methods for validating UI components, displaying validation errors and unsaved changes dialogs. It is used by views and dialogs of the framework and add-ons. You can use it in the application views as well.
5
17
6
18
Below we describe the main methods of the `ViewValidation` bean.
7
19
8
20
[[validateUiComponents]]
9
-
== validateUiComponents
21
+
=== validateUiComponents
10
22
11
23
The `validateUiComponents()` method accepts a collection of components or a component container. It runs validation for all passed components implementing the `SupportsValidation` interface and returns the `ValidationErrors` object which contains validation errors found for the validated components.
12
24
13
-
You can use this method in a view as follows:
25
+
This method is called by detail views during the execution of `closeWithSave()` and `save()` methods.
26
+
27
+
You can call it also in response to user actions, for example:
The `showValidationErrors()` method shows a notification with validation errors, if the passed `ValidationErrors` object is not empty. See the usage example above.
The `showSaveConfirmationDialog()` shows a confirmation dialog about saving or discarding unsaved changes. It is used by xref:views/views.adoc#standard-detail-view[entity detail views] when the user closes the view with unsaved changes and xref:ui-properties.adoc#jmix.ui.view.use-save-confirmation[jmix.ui.view.use-save-confirmation] property is set to `true` (which is the default).
37
51
@@ -54,7 +68,7 @@ dialogs.closeUnsaved.discard = Don't save
54
68
----
55
69
56
70
[[showUnsavedChangesDialog]]
57
-
== showUnsavedChangesDialog
71
+
=== showUnsavedChangesDialog
58
72
59
73
The `showUnsavedChangesDialog()` shows a confirmation dialog about discarding unsaved changes. It is used by xref:views/views.adoc#standard-detail-view[entity detail views] when the user closes the view with unsaved changes and xref:ui-properties.adoc#jmix.ui.view.use-save-confirmation[jmix.ui.view.use-save-confirmation] property is set to `false`.
0 commit comments