New to Telerik UI for Xamarin? Download free 30-day trial

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.

  1. 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.
  2. Create a class MyNonEmptyValidator which inherits from NonEmptyValidatorAttribute,
  3. Set the localization string from the localization manager to the NegativeFeedback property.
public class MyNonEmptyValidator : NonEmptyValidatorAttribute
{
    public MyNonEmptyValidator() : base()
    {
        this.NegativeFeedback = DataFormLocalizationManager.GetString("NegativeFeedback");
    }
}
  1. Set the control to use the ResourceManager of your default resource file:
public partial class MainPage : ContentPage
{
    public MainPage()
    {
        DataFormLocalizationManager.Manager = DataFormResource.ResourceManager;
        InitializeComponent();
    }
}
In this article
Not finding the help you need? Improve this article