示例#1
0
        public static Validator Create(JsonValidationRule rule)
        {
            int minLength = (int)(rule.ValidationParameters["min"] ?? 0);
            int maxLength = (int)(rule.ValidationParameters["max"] ?? Number.MAX_VALUE);

            return(new StringLengthValidator(minLength, maxLength).Validate);
        }
示例#2
0
        public static Validator Create(JsonValidationRule rule)
        {
            Number min = (Number)rule.ValidationParameters["min"];
            Number max = (Number)rule.ValidationParameters["max"];

            return(new RangeValidator(min, max).Validate);
        }
示例#3
0
        public static Validator Create(JsonValidationRule rule)
        {
            int minLength = (int)rule.ValidationParameters["minimumLength"];
            int maxLength = (int)rule.ValidationParameters["maximumLength"];

            return(new StringLengthValidator(minLength, maxLength).Validate);
        }
示例#4
0
        internal static FormContext ParseJsonOptions(JsonValidationOptions options)
        {
            // First hook up the form logic
            FormElement formElement = (FormElement)Document.GetElementById(options.FormId);
            DOMElement  validationSummaryElement = (!ValidationUtil.StringIsNullOrEmpty(options.ValidationSummaryId))
                ? Document.GetElementById(options.ValidationSummaryId)
                : null;

            FormContext formContext = new FormContext(formElement, validationSummaryElement);

            formContext.EnableDynamicValidation();
            formContext.ReplaceValidationSummary = options.ReplaceValidationSummary;

            // Then hook up the field logic
            for (int i = 0; i < options.Fields.Length; i++)
            {
                JsonValidationField field                    = options.Fields[i];
                DOMElement[]        fieldElements            = GetFormElementsWithName(formElement, field.FieldName);
                DOMElement          validationMessageElement = (!ValidationUtil.StringIsNullOrEmpty(field.ValidationMessageId))
                    ? Document.GetElementById(field.ValidationMessageId)
                    : null;

                FieldContext fieldContext = new FieldContext(formContext);
                ArrayList.AddRange((ArrayList)(object)fieldContext.Elements, fieldElements);
                fieldContext.ValidationMessageElement         = validationMessageElement;
                fieldContext.ReplaceValidationMessageContents = field.ReplaceValidationMessageContents;

                // Hook up rules
                for (int j = 0; j < field.ValidationRules.Length; j++)
                {
                    JsonValidationRule rule      = field.ValidationRules[j];
                    Validator          validator = ValidatorRegistry.GetValidator(rule);
                    if (validator != null)
                    {
                        Validation validation = new Validation();
                        validation.FieldErrorMessage = rule.ErrorMessage;
                        validation.Validator         = validator;
                        ArrayList.Add((ArrayList)(object)fieldContext.Validations, validation);
                    }
                }

                fieldContext.EnableDynamicValidation();
                ArrayList.Add((ArrayList)(object)formContext.Fields, fieldContext);
            }

            // hook up callback so that it can be executed by the AJAX code
            ArrayList registeredValidatorCallbacks = (ArrayList)Type.GetField(formElement, "validationCallbacks");

            if (registeredValidatorCallbacks == null)
            {
                registeredValidatorCallbacks = new ArrayList();
                Type.SetField(formElement, "validationCallbacks", registeredValidatorCallbacks);
            }
            Type.InvokeMethod(registeredValidatorCallbacks, "push", (ValidationCallback) delegate() {
                return(ValidationUtil.ArrayIsNullOrEmpty(formContext.Validate("submit")));
            });

            return(formContext);
        }
示例#5
0
 public static Validator Create(JsonValidationRule rule)
 {
     Number min = (Number)rule.ValidationParameters["minimum"];
     Number max = (Number)rule.ValidationParameters["maximum"];
     return new RangeValidator(min, max).Validate;
 }
示例#6
0
 public static Validator Create(JsonValidationRule rule)
 {
     return(new RequiredValidator().Validate);
 }
        public static Validator Create(JsonValidationRule rule)
        {
            string pattern = (string)rule.ValidationParameters["pattern"];

            return(new RegularExpressionValidator(pattern).Validate);
        }
示例#8
0
        public static Validator GetValidator(JsonValidationRule rule)
        {
            ValidatorCreator creator = (ValidatorCreator)Validators[rule.ValidationType];

            return((creator != null) ? creator(rule) : null);
        }
 public static Validator Create(JsonValidationRule rule) {
     return new NumberValidator().Validate;
 }
示例#10
0
 public static Validator GetValidator(JsonValidationRule rule) {
     ValidatorCreator creator = (ValidatorCreator)Validators[rule.ValidationType];
     return (creator != null) ? creator(rule) : null;
 }
示例#11
0
 public static Validator Create(JsonValidationRule rule)
 {
     int minLength = (int)rule.ValidationParameters["minimumLength"];
     int maxLength = (int)rule.ValidationParameters["maximumLength"];
     return new StringLengthValidator(minLength, maxLength).Validate;
 }
 public static Validator Create(JsonValidationRule rule) {
     int minLength = (int)(rule.ValidationParameters["min"] ?? 0);
     int maxLength = (int)(rule.ValidationParameters["max"] ?? Number.MAX_VALUE);
     return new StringLengthValidator(minLength, maxLength).Validate;
 }
示例#13
0
 public static Validator Create(JsonValidationRule rule) {
     return new RequiredValidator().Validate;
 }
 public static Validator Create(JsonValidationRule rule) {
     string pattern = (string)rule.ValidationParameters["pattern"];
     return new RegularExpressionValidator(pattern).Validate;
 }
示例#15
0
 public static Validator Create(JsonValidationRule rule)
 {
     return(new NumberValidator().Validate);
 }