@@ -43,6 +43,35 @@ export type ValidationProvider = (value: string, element: HTMLInputElement, para
43
43
*/
44
44
type Validator = ( ) => Promise < boolean > ;
45
45
46
+ /**
47
+ * Resolves and returns the element referred by original element using ASP.NET selector logic.
48
+ * @param elementName
49
+ */
50
+ function getRelativeFormElement ( elementName : string , selector : string ) {
51
+ // example elementName: Form.PasswordConfirm, Form.Email
52
+ // example selector (dafuq): *.Password, *.__RequestVerificationToken
53
+ // example result element name: Form.Password, __RequestVerificationToken
54
+
55
+ let realSelector = selector . substr ( 2 ) ; // Password, __RequestVerificationToken
56
+ let objectName = '' ;
57
+
58
+ let dotLocation = elementName . lastIndexOf ( '.' ) ;
59
+ if ( dotLocation > - 1 ) {
60
+ // Form
61
+ objectName = elementName . substr ( 0 , dotLocation ) ;
62
+
63
+ // Form.Password
64
+ let relativeElementName = objectName + '.' + realSelector ;
65
+ let relativeElement = document . getElementsByName ( relativeElementName ) [ 0 ] ;
66
+ if ( relativeElement ) {
67
+ return relativeElement ;
68
+ }
69
+ }
70
+
71
+ // __RequestVerificationToken
72
+ return document . getElementsByName ( realSelector ) [ 0 ] ;
73
+ }
74
+
46
75
/**
47
76
* Contains default implementations for ASP.NET Core MVC validation attributes.
48
77
*/
@@ -87,9 +116,7 @@ export class MvcValidationProviders {
87
116
return true ;
88
117
}
89
118
90
- // Sample other parameter: "*.Name"
91
- // Wat?
92
- let otherElement = document . getElementById ( params . other . substr ( 2 ) ) as HTMLInputElement ;
119
+ let otherElement = getRelativeFormElement ( element . name , params . other ) as HTMLInputElement ;
93
120
if ( ! otherElement ) {
94
121
return true ;
95
122
}
0 commit comments