/// <summary> /// Binds form values to a data item and sends messages to client to display validation messages. /// </summary> /// <param name="helper">Form binding helper</param> /// <param name="data">An IData instance</param> /// <returns>True, if there were no binding/validation errors</returns> protected bool BindAndValidate(DataTypeDescriptorFormsHelper helper, IData data) { Dictionary <string, string> errorMessages = helper.BindingsToObject(this.Bindings, data); ValidationResults validationResults = ValidationFacade.Validate(data.DataSourceId.InterfaceType, data); bool isValid = true; if (!validationResults.IsValid) { foreach (ValidationResult result in validationResults) { if (!result.Key.IsNullOrEmpty()) { this.ShowFieldMessage(result.Key, result.Message); } else { this.ShowMessage(DialogType.Error, "Validation error", result.Message); } isValid = false; } } // Checking that required strings are not empty var dataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(data.DataSourceId.InterfaceType); foreach (var fieldName in dataTypeDescriptor.Fields .Where(f => !f.IsNullable && f.InstanceType == typeof(string) && !(f.Inherited && f.Name == "FieldName")) // Skipping validation for inherited IPageMetaData.FieldName .Select(f => f.Name)) { string bindingName = (helper.BindingNamesPrefix ?? "").Replace('.', '_') + fieldName; if (validationResults.Any(r => r.Key == bindingName)) { continue; } object fieldValue = this.Bindings[bindingName]; if (fieldValue is string && (fieldValue as string) == string.Empty && !helper.BindingIsOptional(bindingName)) { this.ShowFieldMessage(bindingName, LocalizationFiles.Composite_Management.Validation_RequiredField); isValid = false; } } if (errorMessages != null) { isValid = false; foreach (var kvp in errorMessages) { this.ShowFieldMessage(kvp.Key, kvp.Value); } } return(isValid); }