I have two issues:
1) On data type validation, I see the row highlight but do not see any error message as a comment that I see in DataAnnotations Support demo
2) How do I add validations like Required field validation or any custom validation at runtime.
I am using 2013.2.724.45 version of telerik controls.
10 Answers, 1 is accepted
As to your questions:
1. The declarative data annotation attributes (i.e. DisplayName) are only supported for auto-generated property definitions by design. Do you have the PropertyDefinitions autogenerated?
2. You can check this forum thread where a similar topic has been discussed.
Regards,
Didie
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Thank you for your response.
AutoGeneratePropertyDefinition is true and I am handling this event to assign grouping, display names and also override templates for few of the fields.
In the WPF telerik controls demo, I have seen even a message 'Value xxx could not be converted' when invalid data is entered. Looks like the telerik control internally handles the type conversion errors and throws this message.
In my case, only the Binding item is known at build all other attributes like display name, grouping, which fields are shown and all of the validations are known only at runtime. How can I add the validations dynamically at runtime. Any sample in this regard is highly appreciated.
I have attached a sample solution to demonstrate the currently supported validation option.
Regards,
Didie
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
I have additionally extended the attached solution to also illustrate validation for Required fields.
Regards,
Didie
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
I am afraid you cannot change the [Required] Data Annotations attribute at runtime.
What you can do is to control this through validation extending the implementation of the IDataErrorInfo interface.
You will have to check the values of the additional criteria you have provided to be configured at runtime and then based on it validate a property as required or do not validate it at all. You can refer to the demo I sent on the implementation of the IDataErrorInfo interface.
Regards,
Didie
Telerik
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
The solution works for updated properties but we need manually trigger validation when submit - save button clicked!
Each item of PropertyDefinitions should trigger own validation rule(s) without updated source!
How can we do it like this way!
Thanks
I am afraid this would not be possible for the time being, what I can suggest you is the approach explained below.
Regards,
Dimitrina
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
public
ConfiguredTemplate GetConfigureTemplate(EAVPropertyAndValue item)
{
FrameworkElementFactory elmFactory =
new
FrameworkElementFactory();
DataTemplate dataTemplate =
new
DataTemplate();
Binding propBinding =
new
Binding
{
Mode = BindingMode.TwoWay,
Source = item,
Path =
new
PropertyPath(
"PropertyValue"
)
};
bool
IsRequired = item.EAVPropertyDefinations.IsRequired;
if
(IsRequired)
{
propBinding.NotifyOnValidationError =
true
;
propBinding.ValidatesOnDataErrors =
true
;
propBinding.ValidatesOnExceptions =
true
;
propBinding.ValidationRules.Add(
new
PropertyRequiredValidator(item.PropertyDefinations.ValidationMessage));
if
(!
string
.IsNullOrWhiteSpace(item.PropertyDefinations.ValidationRegex))
{
propBinding.ValidationRules.Add(
new
RegexValidationRule(item.PropertyDefinations.ValidationRegex, item.PropertyDefinations.ValidationMessage));
}
}
switch
(_metaDataType)
{
case
MetaDataType.String:
elmFactory.Type =
typeof
(TextBox);
elmFactory.SetBinding(TextBox.TextProperty, propBinding);
dataTemplate.VisualTree = elmFactory;
break
;
case
MetaDataType.Date:
elmFactory.Type =
typeof
(RadDateTimePicker);
elmFactory.SetValue(RadDateTimePicker.InputModeProperty, InputMode.DatePicker);
elmFactory.SetBinding(RadDateTimePicker.SelectedValueProperty, propBinding);
dataTemplate.VisualTree = elmFactory;
break
;
case
MetaDataType.GenericCode:
JToken o = JObject.Parse(item.PropertyDefinations.MetaDataSettings);
if
(o[MetaDataSettings.GenericCodeTypeId] !=
null
)
{
long
id = o[MetaDataSettings.GenericCodeTypeId].Value<
long
>();
var genericCodeType = CacheHelperFunctions.GetAllGenericCodeTypes().Where(c => c.ID == id).FirstOrDefault();
var lookups = CacheHelperFunctions.GetAllGenericLookups().Where(x => x.GenericCodeTypeID == id).Select(x => x).ToList();
var itemSource =
new
GenericLookupsComposite
{
GenericCodeTypeDefinition = genericCodeType.Definition,
GenericCodeTypeId = genericCodeType.ID,
IdNamePairs = lookups.Select(n =>
new
IdNamePair { ID = n.ID, Name = n.OptionName }).ToList()
};
Binding sourceBinding =
new
Binding();
sourceBinding.Source = itemSource;
sourceBinding.Mode = BindingMode.TwoWay;
sourceBinding.Path =
new
PropertyPath(
"IdNamePairs"
);
Binding combopropBinding =
new
Binding
{
Mode = BindingMode.TwoWay,
Source = item,
Path =
new
PropertyPath(
"PropertyDataValueKeyId"
),
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
elmFactory.Type =
typeof
(RadComboBox);
elmFactory.SetBinding(RadComboBox.ItemsSourceProperty, sourceBinding);
elmFactory.SetValue(RadComboBox.DisplayMemberPathProperty,
"Name"
);
elmFactory.SetValue(RadComboBox.SelectedValuePathProperty,
"ID"
);
elmFactory.SetValue(RadComboBox.TextProperty, propBinding);
elmFactory.SetBinding(RadComboBox.SelectedValueProperty, combopropBinding);
dataTemplate.VisualTree = elmFactory;
}
break
;
default
:
break
;
}
dataTemplate.Seal();
return
new
ConfiguredTemplate { DataTemplate = dataTemplate, PropertyBinding = propBinding };
}
Above code provides EditorTemplate and Dynamic Binding for Telerik WPF PropertyGrid control. We are trying trigger validation for all propertygrid fields to fill with global Validation.ErrorEvent to the ValidationResult list.
Can we use binding expressions like this or any suggest!?
http://stackoverflow.com/questions/5676202/how-to-force-a-wpf-binding-to-refresh this link sugges
You can try using validator.ValidateObject. That way the validation on the bindings will not be raised. Still, if there are validation errors, you can gather them and show them like a validation summary.
Regards,
Dimitrina
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.