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
The UI for Blazor suite supports and integrates seamlessly into Blazor's Forms and Validation infrastructure. All Telerik UI for Blazor Input components work out of the box when placed inside an `EditForm`, respond to `EditContext` changes and provide default invalid styles.
13
13
14
+
In this article:
15
+
16
+
*[Validation Basics](#validation-basics)
17
+
*[Validation Modes for Simple Inputs](#validation-modes-for-simple-inputs)
18
+
19
+
## Validation Basics
20
+
14
21
To validate the Blazor inputs, you need to:
15
22
16
23
1. Define a model that has the desired [Data Annotation attributes](https://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation).
@@ -34,7 +41,7 @@ This article provides examples of validating the Telerik Blazor components. The
34
41
35
42
>tip Telerik offers the [Form Component]({%slug form-overview%}) that lets you generate and manage forms with predefined layouts and less code.
36
43
37
-
## Simple Inputs
44
+
###Simple Inputs
38
45
39
46
Simple textbox-like inputs do not have any special behavior. You need to bind them to a model field that has the desired data annotation attributes set. Such inputs are the textbox, numeric textbox and date input.
40
47
@@ -139,7 +146,7 @@ Simple textbox-like inputs do not have any special behavior. You need to bind th
139
146
public DateTime? DailyScrum { get; set; }
140
147
141
148
[Required(ErrorMessage = "Enter a starting time")]
ErrorMessage = "Value for {0} must be between {1:dd MMM yyyy HH:mm} and {2:dd MMM yyyy HH:mm}")]
144
151
public DateTime StartTime { get; set; }
145
152
@@ -151,8 +158,8 @@ Simple textbox-like inputs do not have any special behavior. You need to bind th
151
158
[Range(typeof(bool), "true", "true", ErrorMessage = "Must subscribe to the newsletter")]
152
159
public bool SubscribeToNewsletter { get; set; }
153
160
154
-
[Required(ErrorMessage="You should add a note.")]
155
-
[MaxLength(300, ErrorMessage ="Your notes are too long.")]
161
+
[Required(ErrorMessage = "You should add a note.")]
162
+
[MaxLength(300, ErrorMessage ="Your notes are too long.")]
156
163
public string PersonalNotes { get; set; }
157
164
}
158
165
@@ -173,7 +180,7 @@ Simple textbox-like inputs do not have any special behavior. You need to bind th
173
180
}
174
181
````
175
182
176
-
## DropDownList
183
+
###DropDownList
177
184
178
185
The DropDownList always has an item selected - the first item from its data source, the item corresponding to the `Value`, or the item created from the `DefaultText` the developer provides (which has the default value for the type of the Value field - for example, `0` for an `int` and `null` for an `int?` or `string`).
179
186
@@ -234,7 +241,7 @@ This means that for required field validation to work, the current item must hav
234
241
}
235
242
````
236
243
237
-
## RadioGroup
244
+
###RadioGroup
238
245
239
246
The radio group acts in a way similar to a dropdownlist - there is a collection of items that have values, and those values are used to populate a field in the model that is being validated. This lets you define the necessary data annottation attributes on the validated class. Note that required field validation needs nullable fields.
240
247
@@ -292,7 +299,7 @@ The radio group acts in a way similar to a dropdownlist - there is a collection
292
299
````
293
300
294
301
295
-
## ComboBox
302
+
###ComboBox
296
303
297
304
The ComboBox works with the `Value` of the selected item (through its `ValueField`). This means that for required field validation to work, the current item must have a `null` value, or `AllowCustom` must be `true` and the input empty.
298
305
@@ -397,7 +404,7 @@ The ComboBox works with the `Value` of the selected item (through its `ValueFiel
397
404
398
405
399
406
400
-
## MultiSelect
407
+
###MultiSelect
401
408
402
409
The MultiSelect has a value that is a `List` and the validation attributes must take that into account (for example, a regular expression attribute cannot work).
403
410
@@ -445,7 +452,7 @@ The MultiSelect has a value that is a `List` and the validation attributes must
445
452
}
446
453
````
447
454
448
-
## DateRangePicker
455
+
###DateRangePicker
449
456
450
457
The Date Range Picker component consists of two inputs that the user can change independently. They can choose to alter one or both, and the application cannot know their intent - they can change one to an invalid value (for example, a start date that is after the end date), but then intend to change the second input as well.
451
458
@@ -527,7 +534,7 @@ There is no built-in provision in the framework for validating a field value bas
527
534
````
528
535
529
536
530
-
## Editor
537
+
###Editor
531
538
532
539
The Editor produces an HTML string in the field you bind its `Value` to. Thus, while the user may see a certain amount of content, the actual content may have more symbols, because the HTML tags count towards the total string length, but the user does not see them.
533
540
@@ -568,7 +575,7 @@ Unlike other components, the editor does not trigger form validation on every ke
568
575
````
569
576
570
577
571
-
## MaskedTextbox
578
+
###MaskedTextbox
572
579
573
580
The Masked Textbox prompts the user for their input and restricts it according to its [Mask]({%slug maskedtextbox-mask-prompt%}).
574
581
@@ -644,7 +651,7 @@ You may want to set the [`IncludeLiterals`]({%slug maskedtextbox-mask-prompt%}#i
644
651
````
645
652
646
653
647
-
## Sliders
654
+
###Sliders
648
655
649
656
The sliders are, effectively, numeric inputs in terms of behavior and what data they provide. Thus, you can apply the standard validation rules to them.
650
657
@@ -713,7 +720,7 @@ The sliders are, effectively, numeric inputs in terms of behavior and what data
713
720
````
714
721
715
722
716
-
## Color Palette
723
+
###Color Palette
717
724
718
725
The Color Palette component, while not an input, can work with validation so you can, for example, require that the user picks a color. Since it is not an input, it does not have an invalid state, but you can add validation messages around it.
719
726
@@ -748,6 +755,150 @@ The Color Palette component, while not an input, can work with validation so you
748
755
}
749
756
````
750
757
758
+
## Validation Modes for Simple Inputs
759
+
760
+
The simple textbox-like inputs (listed below) can trigger validation at different events. You can customize that through the `ValidateOn` parameter. It takes a member of the `ValidationEvent` enum and provides the following options:
761
+
762
+
*`Input` - (default) - triggers validation on each key press (`oninput`)
763
+
*`Change` - triggers validation on confirmed value change (`OnChange`)
764
+
765
+
The feature is supported by the following components treated as simple textbox-like inputs:
766
+
767
+
* DateInput
768
+
* DatePicker
769
+
* DateTimePicker
770
+
* MaskedTextBox
771
+
* NumericTextBox
772
+
* TextArea
773
+
* TextBox
774
+
* TimePicker
775
+
776
+
>caption Configure the event triggering the input validation
777
+
778
+
````CSHTML
779
+
@using System.ComponentModel.DataAnnotations
780
+
@* This Using is for the model class attributes only *@
781
+
@* The Id parameters are not mandatory for validation, they just show better forms integration *@
Copy file name to clipboardExpand all lines: components/dateinput/overview.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -60,6 +60,8 @@ The date input provides the following features:
60
60
61
61
* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article.
62
62
63
+
*`ValidateOn` - configures the event that will trigger validation (if validation is enabled). Read more at [Validation Modes for Simple Inputs]({%slug common-features/input-validation%}#validation-modes-for-simple-inputs).
Copy file name to clipboardExpand all lines: components/datepicker/overview.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,8 @@ The Blazor Date Picker component exposes the following features:
71
71
72
72
* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article.
73
73
74
+
*`ValidateOn` - configures the event that will trigger validation (if validation is enabled). Read more at [Validation Modes for Simple Inputs]({%slug common-features/input-validation%}#validation-modes-for-simple-inputs).
75
+
74
76
The date picker is, essentially, a [date input]({%slug components/dateinput/overview%}) and a [calendar]({%slug components/calendar/overview%}) and the properties it exposes are mapped to the corresponding properties of these two components. You can read more about their behavior in the respective components' documentation.
Copy file name to clipboardExpand all lines: components/datetimepicker/overview.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -74,6 +74,8 @@ The DateTimePicker component exposes the following features:
74
74
75
75
* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article.
76
76
77
+
*`ValidateOn` - configures the event that will trigger validation (if validation is enabled). Read more at [Validation Modes for Simple Inputs]({%slug common-features/input-validation%}#validation-modes-for-simple-inputs).
78
+
77
79
When using the dropdown to edit dates, you must click the "Set" button to commit the date. It is located in the Time portion of the dropdown (you will be navigated to it automatically upon selecting a date). Clicking "Cancel", or outside of the dropdown without clicking "Set", will revert the time to the original value. You can also commit a date by clicking the "NOW" button which will choose the current time.
78
80
79
81
The time format specifiers in the `Format` control the tumblers available in the dropdown. For example, the `HH` specifier will result in a hour selector in a 24 hour format. If you also add the `tt` specifier, you will also get the AM/PM tumbler, but the 24 hour format will still be used. This means that you can also add several tumblers for the same time portion if the format string repeats them.
Copy file name to clipboardExpand all lines: components/maskedtextbox/overview.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -81,6 +81,8 @@ To use a Telerik MaskedTextbox for Blazor:
81
81
82
82
* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article.
83
83
84
+
*`ValidateOn` - configures the event that will trigger validation (if validation is enabled). Read more at [Validation Modes for Simple Inputs]({%slug common-features/input-validation%}#validation-modes-for-simple-inputs).
Copy file name to clipboardExpand all lines: components/numerictextbox/overview.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -68,6 +68,8 @@ The numeric textbox provides the following features:
68
68
69
69
* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article.
70
70
71
+
*`ValidateOn` - configures the event that will trigger validation (if validation is enabled). Read more at [Validation Modes for Simple Inputs]({%slug common-features/input-validation%}#validation-modes-for-simple-inputs).
Copy file name to clipboardExpand all lines: components/textarea/overview.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -80,6 +80,8 @@ To use the Telerik TextArea in your Blazor application:
80
80
81
81
* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article.
82
82
83
+
*`ValidateOn` - configures the event that will trigger validation (if validation is enabled). Read more at [Validation Modes for Simple Inputs]({%slug common-features/input-validation%}#validation-modes-for-simple-inputs).
84
+
83
85
>caption TextArea with its most common features and symbols counter
Copy file name to clipboardExpand all lines: components/textbox/overview.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -99,6 +99,7 @@ for example: https://demos.telerik.com/blazor-ui/textbox/password
99
99
100
100
* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article.
101
101
102
+
*`ValidateOn` - configures the event that will trigger validation (if validation is enabled). Read more at [Validation Modes for Simple Inputs]({%slug common-features/input-validation%}#validation-modes-for-simple-inputs).
Copy file name to clipboardExpand all lines: components/timepicker/overview.md
+4-2Lines changed: 4 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -70,11 +70,13 @@ The Time Picker component exposes the following features:
70
70
*`Width` - Defines the width of the TimePicker.
71
71
72
72
*`TabIndex` - maps to the `tabindex` attribute of the HTML element. You can use it to customize the order in which the inputs in your form focus with the `Tab` key.
73
-
*
74
-
*`Placeholder` - `string` - maps to the `placeholder` attribute of the HTML element. The `Placeholder` will appear if the component is bound to **nullable** DateTime object - `DateTime?`, but will not be rendered if the component is bound to the default value of a non-nullable DateTime object.
73
+
74
+
*`Placeholder` - `string` - maps to the `placeholder` attribute of the HTML element. The `Placeholder` will appear if the component is bound to **nullable** DateTime object - `DateTime?`, but will not be rendered if the component is bound to the default value of a non-nullable DateTime object.
75
75
76
76
* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article.
77
77
78
+
*`ValidateOn` - configures the event that will trigger validation (if validation is enabled). Read more at [Validation Modes for Simple Inputs]({%slug common-features/input-validation%}#validation-modes-for-simple-inputs).
79
+
78
80
The `Min` and `Max` properties require a `DateTime` object, but will only use the time portion from it. Thus, the date itself is not important. The hours, minutes, seconds and AM/PM portions control the range of the tumblers in the time picker dropdown. They do not impose validation/limitations on the input editing.
79
81
80
82
When using the dropdown to edit dates, you must click the "Set" button to commit the date. Clicking "Cancel", or outside of the dropdown without clicking "Set", will revert the time to the original value. You can also commit a date by clicking the "NOW" button which will choose the current time.
Copy file name to clipboardExpand all lines: knowledge-base/textbox-validate-on-change.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,8 @@ Is there a way to disable this behaviour?
31
31
32
32
We believe that firing the validation immediately makes the user experience more fluid and lets the user know about form issues quickly, which reduces frustration. Thus, we fire validation with the `ValueChanged` event.
33
33
34
+
>tip Telerik UI for Blazor 2.30 adds a `ValidateOn` parameter to input components. It defines the event that triggers validation (`OnChange` or `OnInput`). Read more at [Validation Modes for Simple Inputs]({%slug common-features/input-validation%}#validation-modes-for-simple-inputs).
35
+
34
36
### Differences with standard inputs
35
37
36
38
The standard inputs (such as `InputText` and `InputNumber`) use the `onchange` DOM event to change the `Value` of the model. We have chosen to use `oninput` to provide immediate feedback.
0 commit comments