Skip to content

Commit 3f5d024

Browse files
docs(multiSelect): validation
1 parent c6ed5b4 commit 3f5d024

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

common-features/input-validation.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This article provides examples of validating the Telerik Blazor components. The
2525
* [Simple Inputs](#simple-inputs)
2626
* [DropDownList](#dropdownlist)
2727
* [ComboBox](#combobox)
28+
* [MultiSelect](#multiselect)
2829

2930

3031

@@ -294,6 +295,51 @@ The ComboBox works with the `Value` of the selected item (through its `ValueFiel
294295
````
295296

296297

298+
299+
## MultiSelect
300+
301+
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).
302+
303+
>caption How to validated a MultiSelect
304+
305+
````CSHTML
306+
@using System.ComponentModel.DataAnnotations @* used for the model class attributes *@
307+
308+
<EditForm Model="@person" OnValidSubmit="@HandleValidSubmit">
309+
<DataAnnotationsValidator />
310+
<ValidationSummary />
311+
<p class="languages">
312+
Languages: <TelerikMultiSelect @bind-Value="@person.DevLanguages"
313+
Placeholder="Programming languages you know"
314+
Data="@DevSkills" />
315+
<ValidationMessage For="@(() => person.DevLanguages)"></ValidationMessage>
316+
</p>
317+
318+
<button type="submit">Submit</button>
319+
</EditForm>
320+
321+
@code {
322+
public class Person
323+
{
324+
[Required(ErrorMessage = "You must list the dev skills you have")]
325+
[MinLength(3, ErrorMessage = "At least three languages are required so this application is considered")]
326+
public List<string> DevLanguages { get; set; }
327+
}
328+
329+
Person person = new Person();
330+
331+
List<string> DevSkills = new List<string>
332+
{
333+
"Blazor", "C#", "Python", "C", "C++", "Assembler", "Ruby", "Java", "JavaScript", "HTML", "CSS", "SQL", "PHP"
334+
};
335+
336+
void HandleValidSubmit()
337+
{
338+
Console.WriteLine("OnValidSubmit");
339+
}
340+
}
341+
````
342+
297343
## See Also
298344

299345
* [Data Annotation attributes](https://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation)

0 commit comments

Comments
 (0)