Ejemplo n.º 1
0
        /// <summary>
        /// Do a full clean (validation) on all fields
        /// </summary>
        public override void FullClean()
        {
            base.FullClean(); // Creates an error instance
            if (!this.IsBound)
            {
                return;                // No point continuing
            }
            // Do field by field validation
            var cleanedData = new NameObjectDictionary();

            foreach (KeyValuePair <string, IField> pair in this._fields)
            {
                IField field     = pair.Value;
                string fieldName = this.AddPrefix(pair.Key);
                object value     = field.Widget.GetValueFromDataCollection(this.Data, this.Files, fieldName);
                try
                {
                    cleanedData.Add(pair.Key, field.Clean(value));

                    // Do custom validation
                    if (field.CustomClean != null)
                    {
                        cleanedData = field.CustomClean(cleanedData);
                    }
                }
                catch (ValidationException vex)
                {
                    this.Errors.Add(fieldName, vex.Messages);
                }
            }

            // Do form-wide validation
            try
            {
                this._cleanedData = this.Clean(cleanedData);
            }
            catch (ValidationException vex)
            {
                this.Errors.Add(NonFieldErrors, vex.Messages);
            }
        }