From 4648a252b90af45ca59c3240a8fb86972843b0b2 Mon Sep 17 00:00:00 2001 From: Jamie Phillips Date: Fri, 23 Oct 2015 17:12:24 -0400 Subject: [PATCH] Correcting formatting and handling of error message. Corrected the formatting and correct the handling of the error message. --- .../ValidationRules/UrlAddress.cs | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs b/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs index 3ee7e985d..a44e6d73e 100644 --- a/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs +++ b/src/Orchard.Web/Modules/Orchard.DynamicForms/ValidationRules/UrlAddress.cs @@ -5,10 +5,8 @@ using Orchard.DynamicForms.Services; using Orchard.DynamicForms.Services.Models; using Orchard.Localization; -namespace Orchard.DynamicForms.ValidationRules -{ - public class UrlAddress : ValidationRule - { +namespace Orchard.DynamicForms.ValidationRules { + public class UrlAddress : ValidationRule { public UrlAddress() { RegexOptions = RegexOptions.Singleline | RegexOptions.IgnoreCase; Pattern = @"^http(s)?://([\w-]+.)+[\w-]+(/[\w- ./?%&=])?$"; @@ -17,26 +15,22 @@ namespace Orchard.DynamicForms.ValidationRules public string Pattern { get; set; } public RegexOptions RegexOptions { get; set; } - public override void Validate(ValidateInputContext context) - { - if (!Regex.IsMatch(context.AttemptedValue, Pattern, RegexOptions)) - { + public override void Validate(ValidateInputContext context) { + if (!Regex.IsMatch(context.AttemptedValue, Pattern, RegexOptions)) { var message = GetValidationMessage(context); context.ModelState.AddModelError(context.FieldName, message.Text); } } - public override void RegisterClientAttributes(RegisterClientValidationAttributesContext context) - { + public override void RegisterClientAttributes(RegisterClientValidationAttributesContext context) { context.ClientAttributes["data-val-regex"] = GetValidationMessage(context).Text; context.ClientAttributes["data-val-regex-pattern"] = Pattern; } - private LocalizedString GetValidationMessage(ValidationContext context) - { + private LocalizedString GetValidationMessage(ValidationContext context) { return String.IsNullOrWhiteSpace(ErrorMessage) ? T("{0} is not a valid URL.", context.FieldName) - : new LocalizedString(Tokenize(ErrorMessage, context)); + : T(ErrorMessage); } } }