/// <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()); }
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); }
/// <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()); }
public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType, IBrowserValidationGenerator generator, System.Collections.IDictionary attributes, string target) { base.ApplyBrowserValidation(config, inputType, generator, attributes, target); generator.SetDate(target, BuildErrorMessage()); }
/// <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> /// 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 PrototypeValidationGenerator((PrototypeValidationConfiguration) config, inputType, attributes); }
public new IBrowserValidationGenerator CreateGenerator(BrowserValidationConfiguration config, InputElementType inputType, IDictionary attributes) { return(new PrototypeValidationGeneratorExtension((PrototypeWebValidator.PrototypeValidationConfiguration)config, inputType, attributes)); }
/// <summary> /// Implementors should return their generator instance. /// </summary> /// <param name="configuration"></param> /// <param name="inputType"></param> /// <param name="attributes"></param> /// <returns>A generator instance</returns> public IBrowserValidationGenerator CreateGenerator(BrowserValidationConfiguration configuration, InputElementType inputType, IDictionary attributes) { return new JQueryValidationGenerator((JQueryConfiguration) configuration); }
public override void ApplyBrowserValidation(BrowserValidationConfiguration config, InputElementType inputType, IBrowserValidationGenerator generator, System.Collections.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> /// Implementors should return their generator instance. /// </summary> /// <param name="configuration"></param> /// <param name="inputType"></param> /// <param name="attributes"></param> /// <returns>A generator instance</returns> public IBrowserValidationGenerator CreateGenerator(BrowserValidationConfiguration configuration, InputElementType inputType, IDictionary attributes) { return(new JQueryValidationGenerator((JQueryConfiguration)configuration)); }