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
"content": "@using System.ComponentModel.DataAnnotations\r\n\r\n<Validations Mode=\"ValidationMode.Auto\" Model=\"@model\">\r\n <Validation>\r\n <Field>\r\n <FieldLabel>Country</FieldLabel>\r\n <FieldBody>\r\n <Autocomplete TItem=\"Country\"\r\n TValue=\"string\"\r\n Data=\"@Countries\"\r\n TextField=\"@(( item ) => item.Name)\"\r\n ValueField=\"@(( item ) => item.Iso)\"\r\n Placeholder=\"Select a country\"\r\n @bind-SelectedValue=\"@model.CountryIso\">\r\n <Feedback>\r\n <ValidationError />\r\n </Feedback>\r\n </Autocomplete>\r\n </FieldBody>\r\n </Field>\r\n </Validation>\r\n <Validation>\r\n <Field>\r\n <FieldLabel>Countries</FieldLabel>\r\n <FieldBody>\r\n <Autocomplete TItem=\"Country\"\r\n TValue=\"string\"\r\n Data=\"@Countries\"\r\n TextField=\"@(( item ) => item.Name)\"\r\n ValueField=\"@(( item ) => item.Iso)\"\r\n SelectionMode=\"AutocompleteSelectionMode.Multiple\"\r\n Placeholder=\"Select countries\"\r\n @bind-SelectedValues=\"@model.CountryIsos\">\r\n <Feedback>\r\n <ValidationError />\r\n </Feedback>\r\n </Autocomplete>\r\n </FieldBody>\r\n </Field>\r\n </Validation>\r\n</Validations>\r\n\r\n@code {\r\n [Inject]\r\n public CountryData CountryData { get; set; }\r\n\r\n public IEnumerable<Country> Countries;\r\n\r\n AutocompleteValidationModel model = new AutocompleteValidationModel();\r\n\r\n protected override async Task OnInitializedAsync()\r\n {\r\n Countries = await CountryData.GetDataAsync();\r\n await base.OnInitializedAsync();\r\n }\r\n\r\n public class AutocompleteValidationModel\r\n {\r\n [Required( ErrorMessage = \"Please select a country.\" )]\r\n public string CountryIso { get; set; }\r\n\r\n [MinLength( 1, ErrorMessage = \"Please select at least one country.\" )]\r\n public List<string> CountryIsos { get; set; } = new List<string>();\r\n }\r\n}",
4019
4019
"title": "Validation (data annotations)",
4020
-
"description": "Use ValidationMode.Auto with a model decorated with data annotations to validate single and multiple selections."
4020
+
"description": "Use ValidationMode.Auto with a model decorated with data annotations to validate single and multiple selections. Note: When both Value and Text are bound then validation will work on the Value binding."
0 commit comments