DataForm localization for NonEmptyValidator Attribute
Environment
Product Version | 2021.1.224.1 |
Product | DataForm for Xamarin Cross-Platform |
Description
This how-to article will show you how to localize the DataForm NonemptyValidatorAttribute. The validatior is displayed when the editor shouldn't be empty and the field is required.
For more details about localization in DataForm, please check our help article. Information about validation in Dataform, can be found in DataForm Validation annotations article.
Solution
You can achieve this using custom NonEmptyValidator.
- In case you would like the RadDataForm control to support two languages - English and Spanish - you should add a couple of resource files, for example - DataFormResources.resx and DataFormResources.es.resx. The former will contain the values in English and the latter the values in Spanish.
- Create a class MyNonEmptyValidator which inherits from NonEmptyValidatorAttribute,
- Set the localization string from the localization manager to the NegativeFeedback property.
public class MyNonEmptyValidator : NonEmptyValidatorAttribute
{
public MyNonEmptyValidator() : base()
{
this.NegativeFeedback = DataFormLocalizationManager.GetString("NegativeFeedback");
}
}
- Set the control to use the ResourceManager of your default resource file:
public partial class MainPage : ContentPage
{
public MainPage()
{
DataFormLocalizationManager.Manager = DataFormResource.ResourceManager;
InitializeComponent();
}
}