Example #1
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);
        }
        public FieldContext(FormContext formContext) {
            FormContext = formContext;

            _onBlurHandler = Element_OnBlur;
            _onChangeHandler = Element_OnChange;
            _onInputHandler = Element_OnInput;
            _onPropertyChangeHandler = Element_OnPropertyChange;
        }
Example #3
0
        public FieldContext(FormContext formContext)
        {
            FormContext = formContext;

            _onBlurHandler           = Element_OnBlur;
            _onChangeHandler         = Element_OnChange;
            _onInputHandler          = Element_OnInput;
            _onPropertyChangeHandler = Element_OnPropertyChange;
        }
Example #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;
        }