public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
                                             IBrowserValidationGenerator generator, IDictionary attributes,
                                             string target)
 {
     base.ApplyBrowserValidation(config, inputType, generator, attributes, target);
     generator.SetAsNotSameAs(target, this.propertyToCompare, this.BuildErrorMessage());
 }
Example #2
0
 /// <summary>
 /// Applies the browser validation by setting up one or
 /// more input rules on <see cref="IBrowserValidationGenerator"/>.
 /// </summary>
 /// <param name="config">The config.</param>
 /// <param name="inputType">Type of the input.</param>
 /// <param name="generator">The generator.</param>
 /// <param name="attributes">The attributes.</param>
 /// <param name="target">The target.</param>
 public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
                                             IBrowserValidationGenerator generator, IDictionary attributes,
                                             string target)
 {
     base.ApplyBrowserValidation(config, inputType, generator, attributes, target);
     generator.SetDigitsOnly(target, BuildErrorMessage());
 }
Example #3
0
        /// <summary>
        /// Applies the browser validation by setting up one or
        /// more input rules on <see cref="IBrowserValidationGenerator"/>.
        /// </summary>
        /// <param name="config">The config.</param>
        /// <param name="inputType">Type of the input.</param>
        /// <param name="generator">The generator.</param>
        /// <param name="attributes">The attributes.</param>
        /// <param name="target">The target.</param>
        public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
                                                    IBrowserValidationGenerator generator, IDictionary attributes,
                                                    string target)
        {
            base.ApplyBrowserValidation(config, inputType, generator, attributes, target);

            if (exactLength != int.MinValue)
            {
                string message = string.Format(GetString(MessageConstants.ExactLengthMessage), exactLength);
                generator.SetExactLength(target, exactLength, ErrorMessage ?? message);
            }
            else
            {
                if (minLength != int.MinValue && maxLength != int.MaxValue)
                {
                    string message = string.Format(GetString(MessageConstants.LengthInRangeMessage), minLength, maxLength);
                    generator.SetLengthRange(target, minLength, maxLength, ErrorMessage ?? message);
                }
                else
                {
                    if (minLength != int.MinValue)
                    {
                        string message = string.Format(GetString(MessageConstants.LengthTooShortMessage), minLength);
                        generator.SetMinLength(target, minLength, ErrorMessage ?? message);
                    }
                    if (maxLength != int.MaxValue)
                    {
                        string message = string.Format(GetString(MessageConstants.LengthTooLongMessage), maxLength);
                        generator.SetMaxLength(target, maxLength, ErrorMessage ?? message);
                    }
                }
            }
        }
		/// <summary>
		/// Applies the browser validation by setting up one or
		/// more input rules on <see cref="IBrowserValidationGenerator"/>.
		/// </summary>
		/// <param name="config">The config.</param>
		/// <param name="inputType">Type of the input.</param>
		/// <param name="generator">The generator.</param>
		/// <param name="attributes">The attributes.</param>
		/// <param name="target">The target.</param>
		public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
		                                            IBrowserValidationGenerator generator, IDictionary attributes,
		                                            string target)
		{
			base.ApplyBrowserValidation(config, inputType, generator, attributes, target);
			generator.SetDigitsOnly(target, BuildErrorMessage());
		}
        /// <summary>
        /// Generates a client-side validation script based on the attributes of the modelToValidate.
        /// </summary>
        /// <param name="modelToValidate">The model to validate.</param>
        /// <param name="formId">The client ID of the form.</param>
        /// <param name="propertyNameToElementId">Delegate that can translate properties of the model to form elements.</param>
        /// <returns></returns>
        public string GenerateClientScript(object modelToValidate, string formId, Func <string, string> propertyNameToElementId)
        {
            // Create a BrowserValidationConfiguration instance to store all validation rules.
            BrowserValidationConfiguration config = this._browserValidatorProvider.CreateConfiguration(null);
            // Create a ValidatorRunner that is needed to obtain the validators for the given modelToValidate.
            var validatorRunner = new ValidatorRunner(this._validatorRegistry);
            // Create a script generator and that is linked to the BrowserValidationConfiguration
            IBrowserValidationGenerator generator =
                _browserValidatorProvider.CreateGenerator(config, InputElementType.Undefined, propertyNameToElementId);

            // Get all validators for the given modelToValidate
            IValidator[] validators =
                _validatorRegistry.GetValidators(validatorRunner, modelToValidate.GetType(), RunWhen.Everytime);
            // Iterate the validators and call ApplyBrowserValidation to generate the validation rules and messages into the BrowserValidationConfiguration.
            foreach (var validator in validators)
            {
                validator.ApplyBrowserValidation(config, InputElementType.Undefined, generator, null, propertyNameToElementId(validator.Property.Name));
            }

            // Generate the validation script block
            var sb = new StringBuilder();

            sb.Append("<script type=\"text/javascript\">" + Environment.NewLine);
            // Call CreateBeforeFormClosed of the BrowserValidationConfiguration. This generates the client script.
            // Note: it's called CreateBeforeFormClosed because originally (in Monorail), it was used to only
            // generate some extra scripts for validation.
            sb.Append(config.CreateBeforeFormClosed(formId));
            sb.Append("</script>" + Environment.NewLine);
            return(sb.ToString());
        }
Example #6
0
        /// <summary>
        /// Applies the browser validation by setting up one or
        /// more input rules on <see cref="IBrowserValidationGenerator"/>.
        /// </summary>
        /// <param name="config">The config.</param>
        /// <param name="inputType">Type of the input.</param>
        /// <param name="generator">The generator.</param>
        /// <param name="attributes">The attributes.</param>
        /// <param name="target">The target.</param>
        public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
                                                    IBrowserValidationGenerator generator, IDictionary attributes,
                                                    string target)
        {
            base.ApplyBrowserValidation(config, inputType, generator, attributes, target);

            switch (type)
            {
            case RangeValidationType.Integer:
                generator.SetValueRange(target, (int)min, (int)max, BuildErrorMessage());
                break;

            case RangeValidationType.Long:
                generator.SetValueRange(target, (long)min, (long)max, BuildErrorMessage());
                break;

            case RangeValidationType.Decimal:
                generator.SetValueRange(target, (decimal)min, (decimal)max, BuildErrorMessage());
                break;

            case RangeValidationType.DateTime:
                generator.SetValueRange(target, (DateTime)min, (DateTime)max, BuildErrorMessage());
                break;

            case RangeValidationType.String:
                generator.SetValueRange(target, (string)min, (string)max, BuildErrorMessage());
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #7
0
        /// <summary>
        /// Applies the browser validation by setting up one or
        /// more input rules on <see cref="IBrowserValidationGenerator"/>.
        /// </summary>
        /// <param name="config">The config.</param>
        /// <param name="inputType">Type of the input.</param>
        /// <param name="generator">The generator.</param>
        /// <param name="attributes">The attributes.</param>
        /// <param name="target">The target.</param>
        public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
                                                    IBrowserValidationGenerator generator, IDictionary attributes,
                                                    string target)
        {
            base.ApplyBrowserValidation(config, inputType, generator, attributes, target);

            generator.SetAsLesserThan(target, PropertyToCompare, validationType, BuildErrorMessage());
        }
		/// <summary>
		/// Applies the browser validation by setting up one or
		/// more input rules on <see cref="IBrowserValidationGenerator"/>.
		/// </summary>
		/// <param name="config">The config.</param>
		/// <param name="inputType">Type of the input.</param>
		/// <param name="generator">The generator.</param>
		/// <param name="attributes">The attributes.</param>
		/// <param name="target">The target.</param>
		public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
		                                            IBrowserValidationGenerator generator, IDictionary attributes,
		                                            string target)
		{
		}
Example #9
0
 /// <summary>
 /// Applies the browser validation by setting up one or
 /// more input rules on <see cref="IBrowserValidationGenerator"/>.
 /// </summary>
 /// <param name="config">The config.</param>
 /// <param name="inputType">Type of the input.</param>
 /// <param name="generator">The generator.</param>
 /// <param name="attributes">The attributes.</param>
 /// <param name="name">The name.</param>
 public void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
                                    IBrowserValidationGenerator generator, IDictionary attributes,
                                    string name)
 {
     generator.SetAsGroupValidation(name, Name, BuildErrorMessage());
 }
		/// <summary>
		/// Applies the browser validation by setting up one or
		/// more input rules on <see cref="IBrowserValidationGenerator"/>.
		/// </summary>
		/// <param name="config">The config.</param>
		/// <param name="inputType">Type of the input.</param>
		/// <param name="generator">The generator.</param>
		/// <param name="attributes">The attributes.</param>
		/// <param name="target">The target.</param>
		public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
		                                            IBrowserValidationGenerator generator, IDictionary attributes,
		                                            string target)
		{
			base.ApplyBrowserValidation(config, inputType, generator, attributes, target);

			switch(type)
			{
				case RangeValidationType.Integer:
					generator.SetValueRange(target, (int) min, (int) max, BuildErrorMessage());
					break;
				case RangeValidationType.Long:
					generator.SetValueRange(target, (long)min, (long)max, BuildErrorMessage());
					break;
				case RangeValidationType.Decimal:
					generator.SetValueRange(target, (decimal) min, (decimal) max, BuildErrorMessage());
					break;
				case RangeValidationType.DateTime:
					generator.SetValueRange(target, (DateTime) min, (DateTime) max, BuildErrorMessage());
					break;
				case RangeValidationType.String:
					generator.SetValueRange(target, (string) min, (string) max, BuildErrorMessage());
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}
		}
		/// <summary>
		/// Applies the browser validation by setting up one or
		/// more input rules on <see cref="IBrowserValidationGenerator"/>.
		/// </summary>
		/// <param name="config">The config.</param>
		/// <param name="inputType">Type of the input.</param>
		/// <param name="generator">The generator.</param>
		/// <param name="attributes">The attributes.</param>
		/// <param name="target">The target.</param>
		public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType, IBrowserValidationGenerator generator, System.Collections.IDictionary attributes, string target)
		{
			base.ApplyBrowserValidation(config, inputType, generator, attributes, target);

			generator.SetRegExp(target, @"^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$", BuildErrorMessage());
		}
Example #12
0
 /// <summary>
 /// Applies the browser validation.
 /// </summary>
 /// <param name="config">The config.</param>
 /// <param name="inputType">Type of the input.</param>
 /// <param name="generator">The generator.</param>
 /// <param name="attributes">The attributes.</param>
 /// <param name="target">The target.</param>
 public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
                                             IBrowserValidationGenerator generator, IDictionary attributes,
                                             string target)
 {
     generator.SetEmail(target, BuildErrorMessage());
 }
Example #13
0
 /// <summary>
 /// Applies the browser validation by setting up one or
 /// more input rules on <see cref="IBrowserValidationGenerator"/>.
 /// </summary>
 /// <param name="config">The config.</param>
 /// <param name="inputType">Type of the input.</param>
 /// <param name="generator">The generator.</param>
 /// <param name="attributes">The attributes.</param>
 /// <param name="target">The target.</param>
 public virtual void ApplyBrowserValidation(BrowserValidationConfiguration config,
                                            InputElementType inputType, IBrowserValidationGenerator generator,
                                            IDictionary attributes, string target)
 {
 }
Example #14
0
    public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType, IBrowserValidationGenerator generator, System.Collections.IDictionary attributes, string target)
    {
        base.ApplyBrowserValidation(config, inputType, generator, attributes, target);
        string message = string.Format(defaultErrorMessage, _minLength);

        generator.SetMinLength(target, _minLength, ErrorMessage ?? message);
    }
Example #15
0
		/// <summary>
		/// Applies the browser validation by setting up one or
		/// more input rules on <see cref="IBrowserValidationGenerator"/>.
		/// </summary>
		/// <param name="config">The config.</param>
		/// <param name="inputType">Type of the input.</param>
		/// <param name="generator">The generator.</param>
		/// <param name="attributes">The attributes.</param>
		/// <param name="target">The target.</param>
		public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
		                                            IBrowserValidationGenerator generator, IDictionary attributes,
		                                            string target)
		{
			base.ApplyBrowserValidation(config, inputType, generator, attributes, target);

			if (exactLength != int.MinValue)
			{
				string message = string.Format(GetString(MessageConstants.ExactLengthMessage), exactLength);
				generator.SetExactLength(target, exactLength, ErrorMessage ?? message);
			}
			else
			{
				if (minLength != int.MinValue && maxLength != int.MaxValue)
				{
					string message = string.Format(GetString(MessageConstants.LengthInRangeMessage), minLength, maxLength);
					generator.SetLengthRange(target, minLength, maxLength, ErrorMessage ?? message);
				}
				else
				{
					if (minLength != int.MinValue)
					{
						string message = string.Format(GetString(MessageConstants.LengthTooShortMessage), minLength);
						generator.SetMinLength(target, minLength, ErrorMessage ?? message);
					}
					if (maxLength != int.MaxValue)
					{
						string message = string.Format(GetString(MessageConstants.LengthTooLongMessage), maxLength);
						generator.SetMaxLength(target, maxLength, ErrorMessage ?? message);
					}
				}
			}
		}
Example #16
0
        /// <summary>
        /// Applies the browser validation by setting up one or
        /// more input rules on <see cref="IBrowserValidationGenerator"/>.
        /// </summary>
        /// <param name="config">The config.</param>
        /// <param name="inputType">Type of the input.</param>
        /// <param name="generator">The generator.</param>
        /// <param name="attributes">The attributes.</param>
        /// <param name="target">The target.</param>
        public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType, IBrowserValidationGenerator generator, System.Collections.IDictionary attributes, string target)
        {
            base.ApplyBrowserValidation(config, inputType, generator, attributes, target);

            generator.SetRegExp(target, @"^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})$", BuildErrorMessage());
        }
Example #17
0
 public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType, IBrowserValidationGenerator generator, System.Collections.IDictionary attributes, string target)
 {
 }
Example #18
0
		/// <summary>
		/// Applies the browser validation.
		/// </summary>
		/// <param name="config">The config.</param>
		/// <param name="inputType">Type of the input.</param>
		/// <param name="generator">The generator.</param>
		/// <param name="attributes">The attributes.</param>
		/// <param name="target">The target.</param>
		public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
		                                            IBrowserValidationGenerator generator, IDictionary attributes,
		                                            string target)
		{
			generator.SetEmail(target, BuildErrorMessage());
		}
		/// <summary>
		/// Applies the browser validation by setting up one or
		/// more input rules on <see cref="IBrowserValidationGenerator"/>.
		/// </summary>
		/// <param name="config">The config.</param>
		/// <param name="inputType">Type of the input.</param>
		/// <param name="generator">The generator.</param>
		/// <param name="attributes">The attributes.</param>
		/// <param name="name">The name.</param>
		public void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType,
		                                   IBrowserValidationGenerator generator, IDictionary attributes,
		                                   string name)
		{
			generator.SetAsGroupValidation(name, Name, BuildErrorMessage());
		}