zhaolei
2020-11-20 921de2254ff5712a44ed8575ee8efe34252f6603
commit | author | age
921de2 1 using Microsoft.AspNetCore.Components;
Z 2 using System.Collections.Generic;
3 using System.ComponentModel.DataAnnotations;
4
5 namespace Bootstrap.Admin.Pages.Components
6 {
7     /// <summary>
8     /// 
9     /// </summary>
10     public class EqualToValidator : ValidatorComponentBase
11     {
12         /// <summary>
13         /// 
14         /// </summary>
15         public EqualToValidator()
16         {
17             ErrorMessage = "你的输入不相同";
18         }
19
20         /// <summary>
21         /// 
22         /// </summary>
23         [Parameter]
24         public string Value { get; set; } = "";
25
26         /// <summary>
27         /// 
28         /// </summary>
29         [Parameter]
30         public EventCallback<string> ValueChanged { get; set; }
31
32         /// <summary>
33         /// 
34         /// </summary>
35         /// <param name="propertyValue"></param>
36         /// <param name="context"></param>
37         /// <param name="results"></param>
38         public override void Validate(object? propertyValue, ValidationContext context, List<ValidationResult> results)
39         {
40             var val = propertyValue?.ToString() ?? "";
41             if (val != Value)
42                 results.Add(new ValidationResult(ErrorMessage, new string[] { context.MemberName }));
43         }
44     }
45 }