Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public override string FormatErrorMessage(string name)
        {
            //Get dictionary value for thge required error message
            //WB: UNSURE if this will double check our UmbContext exists or not
            ErrorMessage = UmbracoValidationHelper.FormatErrorMessage(name, ErrorMessageDictionaryKey, DefaultText);

            return(base.FormatErrorMessage(name));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            ErrorMessage = UmbracoValidationHelper.GetDictionaryItem(_errorMessageDictionaryKey);

            var error = FormatErrorMessage(metadata.DisplayName);
            var rule  = new ModelClientValidationRequiredRule(error);

            yield return(rule);
        }
Ejemplo n.º 3
0
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            ErrorMessage = UmbracoValidationHelper.GetDictionaryItem(_errorMessageDictionaryKey, _defaultText);

            var error = FormatErrorMessage(metadata.DisplayName);
            var rule  = new ModelClientValidationEqualToRule(error, _otherProperty);

            yield return(rule);
        }
Ejemplo n.º 4
0
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            ErrorMessage = UmbracoValidationHelper.GetDictionaryItem(_errorMessageDictionaryKey, _defaultText);

            var error = UmbracoValidationHelper.FormatErrorMessage(metadata.DisplayName, _errorMessageDictionaryKey, _defaultText);
            var rule  = new ModelClientValidationRangeRule(error, Minimum, Maximum);

            yield return(rule);
        }
Ejemplo n.º 5
0
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var error = UmbracoValidationHelper.FormatErrorMessage(metadata.DisplayName, ErrorMessageDictionaryKey, DefaultText);
            var rule  = new ModelClientValidationRule
            {
                ErrorMessage   = error,
                ValidationType = "email"
            };

            yield return(rule);
        }
Ejemplo n.º 6
0
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(System.Web.Mvc.ModelMetadata metadata, ControllerContext context)
        {
            ErrorMessage = UmbracoValidationHelper.GetDictionaryItem(_errorMessageDictionaryKey);

            // Kodus to "Chad" http://stackoverflow.com/a/9914117
            yield return(new ModelClientValidationRule
            {
                ErrorMessage = FormatErrorMessage(metadata.DisplayName),
                ValidationType = this.DataType.ToString().ToLower()
            });
        }
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            ErrorMessage = UmbracoValidationHelper.GetDictionaryItem(_errorMessageDictionaryKey);

            var error = FormatErrorMessage(metadata.DisplayName);
            var rule  = new ModelClientValidationRule();

            rule.ErrorMessage   = error;
            rule.ValidationType = "regex";

            rule.ValidationParameters.Add("pattern", this.Pattern);

            yield return(rule);
        }
Ejemplo n.º 8
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            //Convert the value to a bool & check it's true
            if ((bool)value)
            {
                //All good :)
                return(ValidationResult.Success);
            }

            //Get the error message to return
            var error = UmbracoValidationHelper.FormatErrorMessage(validationContext.DisplayName, ErrorMessageDictionaryKey);

            //Return error
            return(new ValidationResult(error));
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="metadata"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public IEnumerable <ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var item = UmbracoValidationHelper.GetDictionaryItem(_errorMessageDictionaryKeyOrFallback);

            // Make sure that item is not just the default key
            if (item != DEFAULT_ERROR_MESSAGE_DICTIONARY_KEY)
            {
                // item is not the default key

                // Try to format error message with specified key or fallback
                this.TrySetErrorMessage(_errorMessageDictionaryKeyOrFallback);
            }

            var error = FormatErrorMessage(metadata.DisplayName);
            var rule  = new ModelClientValidationRequiredRule(error);

            yield return(rule);
        }
Ejemplo n.º 10
0
        static public void TrySetErrorMessage(this ValidationAttribute attr, string dictionaryKey)
        {
            if (string.IsNullOrEmpty(dictionaryKey))
            {
                return;
            }

            var item = UmbracoValidationHelper.GetDictionaryItem(dictionaryKey);

            if (item != dictionaryKey)
            {
                // dictionaryKey has entry in dictionary, use entry value as error message
                attr.ErrorMessage = item;
            }
            else
            {
                // dictionaryKey does not have entry in dictionary, assume it is error message
                attr.ErrorMessage = dictionaryKey;
            }
        }
Ejemplo n.º 11
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var email = Convert.ToString(value);

            if (!string.IsNullOrEmpty(email))
            {
                //Test the regex
                var result = _regex.Match(email).Length > 0;

                //If no matches then email NOT valid
                if (!result)
                {
                    //Get the error message to return
                    var error = UmbracoValidationHelper.FormatErrorMessage(validationContext.DisplayName, ErrorMessageDictionaryKey, DefaultText);

                    //Return error
                    return(new ValidationResult(error));
                }
            }

            //All good :)
            return(ValidationResult.Success);
        }