Unplanned
Last Updated: 05 Jun 2020 06:07 by ADMIN
Alessio Bulleri
Created on: 05 Jun 2020 06:07
Category: ValidationProvider
Type: Feature Request
0
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".

Workaround: 

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()
        {
            InitializeComponent();

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

            radValidationProvider1.ValidationRules.Add(radValidationRule1);

            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;
            }
        }

0 comments