public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { ErrorMessage = UmbracoPropertyValidationHelper.GetPropertyValueItem(_errorMessageKey); var error = FormatErrorMessage(metadata.DisplayName); string errorMessage = StringBuilderMessageStringLength.Message(error, MinimumLength, MaximumLength); var rule = new ModelClientValidationStringLengthRule($"{_errorFieldName} - {errorMessage}", MinimumLength, MaximumLength); yield return(rule); }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { //Needed if javascript disabled ErrorMessage = UmbracoPropertyValidationHelper.GetPropertyValueItem(_errorMessageKey); var error = FormatErrorMessage(validationContext.DisplayName); string errorMessage = StringBuilderMessageStringLength.Message(error, MinimumLength, MaximumLength); if (IsValid(value)) { return(ValidationResult.Success); } return(new ValidationResult(_errorFieldName + " " + errorMessage + " " + "Javascript disabled")); }