mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding PasswordField and improving validation API.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using Orchard.DynamicForms.Helpers;
|
||||
using Orchard.DynamicForms.Services;
|
||||
using Orchard.DynamicForms.Services.Models;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.DynamicForms.ValidationRules {
|
||||
public class Compare : ValidationRule {
|
||||
public string TargetName { get; set; }
|
||||
|
||||
public override void Validate(ValidateInputContext context) {
|
||||
var targetValue = context.Values[TargetName];
|
||||
if (!String.Equals(context.AttemptedValue, targetValue)) {
|
||||
var message = GetValidationMessage(context);
|
||||
context.ModelState.AddModelError(context.FieldName, message.Text);
|
||||
}
|
||||
}
|
||||
|
||||
public override void RegisterClientAttributes(RegisterClientValidationAttributesContext context) {
|
||||
context.ClientAttributes["data-val-equalto"] = GetValidationMessage(context).Text;
|
||||
context.ClientAttributes["data-val-equalto-other"] = "*." + TargetName;
|
||||
}
|
||||
|
||||
private LocalizedString GetValidationMessage(ValidationContext context) {
|
||||
return T(ErrorMessage.WithDefault("{0} must match the value of {1}."), context.FieldName, TargetName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user