nhibernate.validator 和 x.Val& 带有自定义验证器的 jQuery
我一直在使用 nhibernate.validator 和 xVal 以及 JQuery,它们配合得很好,直到我尝试使用自定义验证器。 根据 xVal codeplex 端,如果自定义验证器实现了 ICustomRule 接口,则支持它们。 并且您提供 ToCustomRule 函数,该函数返回一个 customRule,其中包含将执行客户端验证的 Javascript 函数的名称。
我的验证器正在服务器端使用,但它没有附加到客户端的字段。
以下是代码的重要部分:
正在验证的属性:
_
Public Property Password() As String
Get
Return m_Password
End Get
Set(ByVal value As String)
m_Password = value
End Set
End Property
自定义验证器:
Imports NHibernate.Validator.Engine
Imports xVal.RuleProviders
Imports xVal.Rules
_
_
Public Class PasswordValidationAttribute
Inherits Attribute
Implements IRuleArgs
Private m_Message As String = "Password and Confirm Password must be the same"
Public Property Message() As String Implements NHibernate.Validator.Engine.IRuleArgs.Message
Get
Return m_Message
End Get
Set(ByVal value As String)
m_Message = value
End Set
End Property
End Class
Public Class PasswordValidator
Implements IValidator, ICustomRule
Public Function IsValid(ByVal value As Object) As Boolean Implements NHibernate.Validator.Engine.IValidator.IsValid
Dim valid As Boolean = True
Dim val As String = CType(value, String)
If val = "hello" Then
valid = True
Else
valid = False
End If
Return valid
End Function
Public Function ToCustomRule() As xVal.Rules.CustomRule Implements xVal.RuleProviders.ICustomRule.ToCustomRule
Return New CustomRule("ValidatePassword", Nothing, "Password and Password Confirmation must Match")
End Function
End Class
这是由 html.ClientSideValidation(用户)在源中生成的内容的重要部分,
{"FieldName":"Password","FieldRules":[{"RuleName":"Required","RuleParameters":{},"Message":"Password is Required"}]},
它附加了所需的字段验证器,但不是定制一.
谁能帮我这个? 这是一个非常关键的功能!
谢谢你!
I've been playing with nhibernate.validator and xVal and JQuery and they work together quite nicely, until I try to have custom validators. According to the xVal codeplex side custom validators are supported if they implement the ICustomRule interface. and you supply the ToCustomRule function which returns a customRule with the name of the Javascript function that will do the client side validation.
My validator is being used on the server side, but it isn't getting attached to the field on the client side.
here are the important parts of the code:
The property that is being validated:
_
Public Property Password() As String
Get
Return m_Password
End Get
Set(ByVal value As String)
m_Password = value
End Set
End Property
The Custom Validator:
Imports NHibernate.Validator.Engine
Imports xVal.RuleProviders
Imports xVal.Rules
_
_
Public Class PasswordValidationAttribute
Inherits Attribute
Implements IRuleArgs
Private m_Message As String = "Password and Confirm Password must be the same"
Public Property Message() As String Implements NHibernate.Validator.Engine.IRuleArgs.Message
Get
Return m_Message
End Get
Set(ByVal value As String)
m_Message = value
End Set
End Property
End Class
Public Class PasswordValidator
Implements IValidator, ICustomRule
Public Function IsValid(ByVal value As Object) As Boolean Implements NHibernate.Validator.Engine.IValidator.IsValid
Dim valid As Boolean = True
Dim val As String = CType(value, String)
If val = "hello" Then
valid = True
Else
valid = False
End If
Return valid
End Function
Public Function ToCustomRule() As xVal.Rules.CustomRule Implements xVal.RuleProviders.ICustomRule.ToCustomRule
Return New CustomRule("ValidatePassword", Nothing, "Password and Password Confirmation must Match")
End Function
End Class
and this isthe important part of what is generated in the source by the html.ClientSideValidation(of user)
{"FieldName":"Password","FieldRules":[{"RuleName":"Required","RuleParameters":{},"Message":"Password is Required"}]},
It's attaching the required field validator but not the custom one.
Can anyone help me with this? It's a pretty key bit of functionality!
Thank You!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您不调用
xVal.ActiveRuleProviders.Providers.Clear()
,或者如果您调用,请确保像这样添加 CustomRulesProviderxVal.ActiveRuleProviders.Providers.Add(new xVal.RuleProviders. CustomRulesProvider())
Ensure you don´t call
xVal.ActiveRuleProviders.Providers.Clear()
or if you do, then ensure you add CustomRulesProvider like thisxVal.ActiveRuleProviders.Providers.Add(new xVal.RuleProviders.CustomRulesProvider())
我最终放弃了这个并使用了最新版本的 XVal 中添加的一些远程验证规则。
I ended up ditching this and using some remote validation rules that were added in the newest version of XVal.