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()); }
/// <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> /// 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); 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, 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) { }
/// <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()); }
/// <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()); }
/// <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) { }
/// <summary> /// Implementors should return their generator instance. /// </summary> /// <param name="configuration"></param> /// <param name="inputType"></param> /// <param name="propertyNameToElementId"></param> /// <returns>A generator instance</returns> public IBrowserValidationGenerator CreateGenerator(BrowserValidationConfiguration configuration, InputElementType inputType, Func<string, string> propertyNameToElementId) { return new JQueryValidationGenerator((JQueryConfiguration)configuration, inputType, propertyNameToElementId); }
/// <summary> /// Creates a form tag based on the parameters. /// <para> /// Javascript validation can also be bound to /// the form and|or elements nested as long as the helper is /// able to reach the <see cref="Type"/> of the object used on your view code /// </para> /// <para> /// The action attribute generation will use <see cref="UrlHelper"/> /// </para> /// </summary> /// /// <example> /// /// <code lang="none"> /// $Form.FormTag('mytarget.castle', "%{id='productform'}") /// </code> /// /// Outputs: /// /// <code lang="xml"> /// <form method='post' action='mytarget.castle' id='productform'> /// </code> /// /// </example> /// /// <remarks> /// The following parameters are accepted. /// /// <list type="table"> /// <term> /// <term>method</term> /// <description>string. The http method to use. Defaults to <c>post</c></description> /// </term> /// <term> /// <term>id</term> /// <description>string. The form id.</description> /// </term> /// </list> /// /// More parameters can be accepted depending on the form validation strategy you are using (if any). /// /// </remarks> /// /// <param name="url">The hardcoded url.</param> /// <param name="parameters">The parameters for the tag or for action and form validation generation.</param> /// <returns></returns> public string FormTag(string url, IDictionary parameters) { string method = CommonUtils.ObtainEntryAndRemove(parameters, "method", "post"); currentFormId = CommonUtils.ObtainEntryAndRemove(parameters, "id", "form" + ++formCount); validationConfig = validatorProvider.CreateConfiguration(parameters); string afterFormTag = IsValidationEnabled ? validationConfig.CreateAfterFormOpened(currentFormId) : String.Empty; string formContent; if (url != null) { formContent = "<form action='" + url + "' method='" + method + "' " + "id='" + currentFormId + "' " + GetAttributes(parameters) + ">"; } else { formContent = "<form method='" + method + "' id='" + currentFormId + "' " + GetAttributes(parameters) + ">"; } return formContent + afterFormTag; }
/// <summary> /// Implementors should return their generator instance. /// </summary> /// <param name="config"></param> /// <param name="inputType"></param> /// <param name="attributes"></param> /// <returns>A generator instance</returns> public IBrowserValidationGenerator CreateGenerator(BrowserValidationConfiguration config, InputElementType inputType, IDictionary attributes) { return new FValidateGenerator(inputType, attributes); }
/// <summary> /// Generate Ajax form tag for ajax based form submission. Experimental. /// </summary> /// <param name="parameters"></param> /// <returns></returns> public string AjaxFormTag(IDictionary parameters) { currentFormId = CommonUtils.ObtainEntryAndRemove(parameters, "id", "form" + ++formCount); validationConfig = validatorProvider.CreateConfiguration(parameters); string afterFormTag = IsValidationEnabled ? validationConfig.CreateAfterFormOpened(currentFormId) : String.Empty; string url = UrlHelper.For(parameters); parameters["form"] = true; if (parameters.Contains("onsubmit")) { string onSubmitFunc = CommonUtils.ObtainEntryAndRemove(parameters, "onsubmit"); //remove return to make it compatible for ajax condition if (onSubmitFunc.StartsWith("return ", StringComparison.InvariantCultureIgnoreCase)) { onSubmitFunc = onSubmitFunc.Substring(7); } if (onSubmitFunc.EndsWith(";", StringComparison.InvariantCultureIgnoreCase)) { onSubmitFunc = onSubmitFunc.Remove(onSubmitFunc.Length - 1); } string conditionFunc = CommonUtils.ObtainEntryAndRemove(parameters, "condition", string.Empty); if (!string.IsNullOrEmpty(conditionFunc)) { conditionFunc += " && "; } conditionFunc += onSubmitFunc; parameters["condition"] = conditionFunc; } bool isMethodAssigned = parameters.Contains("method"); string method = CommonUtils.ObtainEntryAndRemove(parameters, "method", "post"); parameters["url"] = url; // reassign method so in case if there is no value the default is assigned. if (isMethodAssigned) { parameters["method"] = method; } String remoteFunc = new AjaxHelper().RemoteFunction(parameters); string formContent = String.Format("<form id='{1}' method='{2}' {3} onsubmit=\"{0}; return false;\" enctype=\"multipart/form-data\">", remoteFunc, currentFormId, method,GetAttributes(parameters)); return formContent + afterFormTag; }