Last Updated: 21 Aug 2020 12:32 by ADMIN
Release R3 2020 (LIB 2020.2.826)
Alessio Bulleri
Created on: 05 Jun 2020 06:07
Category: ValidationProvider
Type: Feature Request
RadValidationProvider: add support for nested PropertyNames to validate Text Length

RadValidationRule allows you to define a rule for a certain control by specifying the PropertyName that has to be validated. However, RadTextBox doesn't offer a property that specifies how many symbols are entered in the editor. This can be checked by the RadTextBox.Text.Length property.  It would be nice to have support for defining nested properties in the validation rules: RadValidationRule.PropertyName ="Text.Length".


The possible solution that I can suggest is to add a RadValidationRule for empty Text and in addition to this handle the ControlValidation event which occurs before a RadEditorControl is being validated. The RadValidationEventArgs gives very useful information about the tool tip error indication, validation rule, etc. The IsValid argument allows you to override the default result indicating whether the validation fails and change the error message accordingly: 

        public RadForm1()

            RadValidationRule radValidationRule1 = new RadValidationRule();
            radValidationRule1.AutoToolTip = true;
            radValidationRule1.Operator = Telerik.WinControls.Data.FilterOperator.IsNotLike;
            radValidationRule1.PropertyName = "Text";
            radValidationRule1.ToolTipText = "Text is empty!";
            radValidationRule1.Value = "";


            this.radValidationProvider1.ControlValidation += radValidationProvider1_ControlValidation;

        private void radValidationProvider1_ControlValidation(object sender, RadValidationEventArgs e)
            if (e.Control == this.radTextBox1 && this.radTextBox1.Text != string.Empty &&
                this.radTextBox1.TextBoxElement.TextBoxItem.TextLength < 20)
                e.ErrorText = "Text is less than 20 characters !";
                e.IsValid = false;